From: Aino on 10 Aug 2010 10:07 Here a simple, annoying problem: qmax=6; Q=[-qmax:2:-2,-1:0.4:1,2:2:qmax]' Q = -6.000000000000000 -4.000000000000000 -2.000000000000000 -1.000000000000000 -0.600000000000000 -0.200000000000000 0.200000000000000 0.600000000000000 1.000000000000000 2.000000000000000 4.000000000000000 6.000000000000000 >> q=-4 q = -4 >> find(Q==q) ans = 2 *Works! >> q=0.2 q = 0.200000000000000 >> find(Q==q) ans = Empty matrix: 0-by-1 *Doesn't work.. >> whos Name Size Bytes Class Attributes Q 12x1 96 double ans 0x1 0 double q 1x1 8 double qmax 1x1 8 double Why does find not find? -Aino
From: dpb on 10 Aug 2010 10:07 Aino wrote: > Here a simple, annoying problem: .... [example of floating point elided for brevity] .... > Why does find not find? See the ML FAQ at <http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F> --
From: Sean on 10 Aug 2010 10:13 "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <i3rme9$12$1(a)fred.mathworks.com>... > Here a simple, annoying problem: > > qmax=6; > Q=[-qmax:2:-2,-1:0.4:1,2:2:qmax]' > > Q = > > -6.000000000000000 > -4.000000000000000 > -2.000000000000000 > -1.000000000000000 > -0.600000000000000 > -0.200000000000000 > 0.200000000000000 > 0.600000000000000 > 1.000000000000000 > 2.000000000000000 > 4.000000000000000 > 6.000000000000000 > > >> q=-4 > q = > -4 > > >> find(Q==q) > ans = > 2 > > *Works! > > >> q=0.2 > q = > 0.200000000000000 > > >> find(Q==q) > ans = > Empty matrix: 0-by-1 > > *Doesn't work.. > > >> whos > Name Size Bytes Class Attributes > > Q 12x1 96 double > ans 0x1 0 double > q 1x1 8 double > qmax 1x1 8 double > > Why does find not find? > > -Aino Question 6.1 http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Aino on 10 Aug 2010 10:54 "Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i3rmpg$m4m$1(a)fred.mathworks.com>... > "Aino" <aino.tietavainen(a)removeThis.helsinki.fi> wrote in message <i3rme9$12$1(a)fred.mathworks.com>... > > Here a simple, annoying problem: > > > > qmax=6; > > Q=[-qmax:2:-2,-1:0.4:1,2:2:qmax]' > > > > Q = > > > > -6.000000000000000 > > -4.000000000000000 > > -2.000000000000000 > > -1.000000000000000 > > -0.600000000000000 > > -0.200000000000000 > > 0.200000000000000 > > 0.600000000000000 > > 1.000000000000000 > > 2.000000000000000 > > 4.000000000000000 > > 6.000000000000000 > > > > >> q=-4 > > q = > > -4 > > > > >> find(Q==q) > > ans = > > 2 > > > > *Works! > > > > >> q=0.2 > > q = > > 0.200000000000000 > > > > >> find(Q==q) > > ans = > > Empty matrix: 0-by-1 > > > > *Doesn't work.. > > > > >> whos > > Name Size Bytes Class Attributes > > > > Q 12x1 96 double > > ans 0x1 0 double > > q 1x1 8 double > > qmax 1x1 8 double > > > > Why does find not find? > > > > -Aino > > Question 6.1 > http://matlabwiki.mathworks.com/MATLAB_FAQ Hi, and so it is, that find(abs(Q-q) < 10^(-5)) works. :) Thank you, Aino
|
Pages: 1 Prev: Reading a PDF file Next: ??? Undefined function or variable |