"find" function doesn't work

Hi~ I got a weird problem here. See the attached picture. "find" works for some values and doesn't for some others. It could a stupid question but can anybody help? Thanks a lot!
So the wavelength vector "lem" has some value but "find" can't find it.
The following is what happens in the command window. It can find the number value but can't find the variable x which equals that value.
>> x
x =
507.0350
>> jj = find(lem==x)
jj =
Empty matrix: 1-by-0
>> jj = find(lem==507.0350)
jj =
3408

 Accepted Answer

find() works fine. Your array does not contain the value in x. If you were to try
lem(3408) - x
you would find that the result is non-zero.

6 Comments

oh Thanks a lot Walter!
yes you're right.
I got this:
>> lem(3408)-x
ans =
5.6843e-014
Let me carefully check the values.
Hi Walter, Hi everybody, could you help more?
I actually don't know how to handle this small difference in value.
>> format('long')
>> x
x =
5.070350000000000e+002
>> lem(3408)
ans =
5.070350000000000e+002
>> lem(3408)-x
ans =
5.684341886080802e-014
they are double precision variables. Thanks~
>> whos x
Name Size Bytes Class Attributes
x 1x1 8 double
>> whos lem
Name Size Bytes Class Attributes
lem 1x80001 640008 double
Hi~ Thanks for the help, Walter.
I read something about this flow point error here http://www.mathworks.com/help/techdoc/matlab_prog/f2-12135.html?#bqxyrhp.
I currently use this to deal:
>> jj = find(floor(10000000000*(lem-x))==0)
jj =
3408
it works. Thanks! Let me know if there are better ways to solve this problem. Thanks!
actually
jj = find(abs(10000000000*(lem-x))<1)
is a better way. because the error could be >0 or <0.
if it was -1e-14, floor(-1e-14)=-1
Please examine the documentation for eps()

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!