From: Luna Moon on 23 Jun 2010 15:43 Here is the number I want to find, let's call it x, here is the big vector, let me call it A, I want to find the number x in A, in a fuzzy way. Lets do an example: x=3, A=[0, 1, 2, 3, 4, 5], then I want to identify the target location to be position 4. Another example: x=3, A=[0, 2, 4, 6, 8], then I want to identify the target locations to be positions 2 and 3, (i.e. the immediate location right before the placehold that x should be in, and one immediately after...) i.e. x=3 should have been in between 2 and 3, since we couldn't find it in the vector A is an ordered vector... not a set... How to do that? thanks
From: John D'Errico on 23 Jun 2010 15:52 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <57dc7fe3-2b8b-4ed7-870c-b73c87ae24d4(a)a3g2000vbl.googlegroups.com>... > Here is the number I want to find, let's call it x, > > here is the big vector, let me call it A, > > I want to find the number x in A, in a fuzzy way. > > Lets do an example: x=3, A=[0, 1, 2, 3, 4, 5], > then I want to identify the target location to be position 4. > > Another example: > x=3, A=[0, 2, 4, 6, 8], > then I want to identify the target locations to be positions 2 and 3, > (i.e. the immediate location right before the placehold that x should > be in, and one immediately after...) > i.e. x=3 should have been in between 2 and 3, since we couldn't find > it in the vector > > A is an ordered vector... not a set... > > How to do that? You won't believe me. People never do on this matter. But the second return argument from histc does exactly this. HTH, John
From: Roger Stafford on 23 Jun 2010 15:57 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <57dc7fe3-2b8b-4ed7-870c-b73c87ae24d4(a)a3g2000vbl.googlegroups.com>... > Here is the number I want to find, let's call it x, > > here is the big vector, let me call it A, > > I want to find the number x in A, in a fuzzy way. > > Lets do an example: x=3, A=[0, 1, 2, 3, 4, 5], > then I want to identify the target location to be position 4. > > Another example: > x=3, A=[0, 2, 4, 6, 8], > then I want to identify the target locations to be positions 2 and 3, > (i.e. the immediate location right before the placehold that x should > be in, and one immediately after...) > i.e. x=3 should have been in between 2 and 3, since we couldn't find > it in the vector > > A is an ordered vector... not a set... > > How to do that? > > thanks [ignore,bin] = histc(x,A); Roger Stafford
From: Luna Moon on 23 Jun 2010 16:12 On Jun 23, 3:57 pm, "Roger Stafford" <ellieandrogerxy...(a)mindspring.com.invalid> wrote: > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <57dc7fe3-2b8b-4ed7-870c-b73c87ae2...(a)a3g2000vbl.googlegroups.com>... > > Here is the number I want to find, let's call it x, > > > here is the big vector, let me call it A, > > > I want to find the number x in A, in a fuzzy way. > > > Lets do an example: x=3, A=[0, 1, 2, 3, 4, 5], > > then I want to identify the target location to be position 4. > > > Another example: > > x=3, A=[0, 2, 4, 6, 8], > > then I want to identify the target locations to be positions 2 and 3, > > (i.e. the immediate location right before the placehold that x should > > be in, and one immediately after...) > > i.e. x=3 should have been in between 2 and 3, since we couldn't find > > it in the vector > > > A is an ordered vector... not a set... > > > How to do that? > > > thanks > > [ignore,bin] = histc(x,A); > > Roger Stafford- Hide quoted text - > > - Show quoted text - Great idea but ... Slightly off... I have to use one more "if" to fix it... >> x=3, A=[0, 1, 2, 3, 4, 5], [ignore,bin] = histc(x,A) x = 3 A = 0 1 2 3 4 5 ignore = 0 0 0 1 0 0 bin = 4 >> x=3, A=[0, 1, 2, 4, 5], [ignore,bin] = histc(x,A) x = 3 A = 0 1 2 4 5 ignore = 0 0 1 0 0 bin = 3
From: John D'Errico on 23 Jun 2010 16:28
Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <59fedfc4-9c35-400f-86ed-a7acbc9bc75b(a)20g2000vbi.googlegroups.com>... > On Jun 23, 3:57 pm, "Roger Stafford" > <ellieandrogerxy...(a)mindspring.com.invalid> wrote: > > Luna Moon <lunamoonm...(a)gmail.com> wrote in message <57dc7fe3-2b8b-4ed7-870c-b73c87ae2...(a)a3g2000vbl.googlegroups.com>... > > > Here is the number I want to find, let's call it x, > > > > > here is the big vector, let me call it A, > > > > > I want to find the number x in A, in a fuzzy way. > > > > > Lets do an example: x=3, A=[0, 1, 2, 3, 4, 5], > > > then I want to identify the target location to be position 4. > > > > > Another example: > > > x=3, A=[0, 2, 4, 6, 8], > > > then I want to identify the target locations to be positions 2 and 3, > > > (i.e. the immediate location right before the placehold that x should > > > be in, and one immediately after...) > > > i.e. x=3 should have been in between 2 and 3, since we couldn't find > > > it in the vector > > > > > A is an ordered vector... not a set... > > > > > How to do that? > > > > > thanks > > > > [ignore,bin] = histc(x,A); > > > > Roger Stafford- Hide quoted text - > > > > - Show quoted text - > > > Great idea but ... > > Slightly off... I have to use one more "if" to fix it... > > >> x=3, A=[0, 1, 2, 3, 4, 5], [ignore,bin] = histc(x,A) > > x = > > 3 > > > A = > > 0 1 2 3 4 5 > > > ignore = > > 0 0 0 1 0 0 > > > bin = > > 4 > > >> x=3, A=[0, 1, 2, 4, 5], [ignore,bin] = histc(x,A) > > x = > > 3 > > > A = > > 0 1 2 4 5 > > > ignore = > > 0 0 1 0 0 > > > bin = > > 3 So, pray tell, how is that NOT what you asked for? bin is the number of the bin that x falls in. EXACTLY so. If you want to know the lower end point of that bin, then what does A(bin) give you? John |