f



"find"can't find?

I've found very funny situation with my matlab6.5.
a=0:0.1:1
b=find(a==0.3)

Then, ans is supposed to be 4, however,

>>Empty matrix: 1-by-0
0
jsywind (1)
4/4/2009 11:43:01 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
586 Views

Similar Articles

[PageSpeed] 16

On Apr 4, 5:43 pm, "Seungyong " <jsyw...@gmaildot.com> wrote:
> I've found very funny situation with my matlab6.5.
> a=0:0.1:1
> b=find(a==0.3)
>
> Then, ans is supposed to be 4, however,
>
> >>Empty matrix: 1-by-0

This is a variation on a frequently asked question.  The answer is
simply that the decimal number 0.3 cannot be represented exactly in
the double precision floating point arithmetic used by MATLAB.  This
becomes obvious if you do the following:

>> fprintf('%.18e\n',0.3);
2.999999999999999889e-01

Another example that illustrated this is:

>> 0.3-3*0.1

ans =

    -5.551115123125783e-17

0
4/4/2009 11:47:42 PM
Many others have found this same issue:


http://www.mathworks.com/matlabcentral/newsreader/view_thread/246492#635355
http://www.mathworks.com/matlabcentral/newsreader/view_thread/248012#639482
http://www.mathworks.com/matlabcentral/newsreader/view_thread/247439#637704
0
spamanon (2437)
4/5/2009 6:43:04 AM
Reply: