Vector position / Comparison ==

25 views
Skip to first unread message

Alyenz

unread,
Jul 6, 2008, 6:27:53 PM7/6/08
to The MATLAB users
Hi,

I have 2 vectors.
Example of vector A = [1.5 3.5 2.5 3 0.5 1 3 0.5 1.5 0.5...]
Example of vector B = [ 0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 ....]

I need a vector C where to put , for each value in vector A, its
position in vector B
I need C = [ 4 8 6 7 2 3 6 2 4 2 ]

I am doing it with a 'for' loop and 'find' operation:
for i=1:10; find(B==A(i))
end

BUT i have the following problem.
Some values at vector A are not equal to values in vector B. For
example
A(2) = 3.499999999999999 and B(8)=3.5

And the 'for' loops gives me an error.

My questions are:
Is there some way to solve the == problem?
How can I find the nearest value (not the exact one)?


Thanks in advance

cesar

Alex Frid

unread,
Jul 7, 2008, 1:29:20 AM7/7/08
to matlab...@googlegroups.com
Hi,
you can write in side the find function more complex expression like:
>> find(B<A(i)+threshold & B>A(i)-threshold)
where the threshold value will be your accuracy expectation.

Hope it helped.
--
Alex Frid
//////
( ' , ' )
<!==!>
|_|_|
Reply all
Reply to author
Forward
0 new messages