Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Find doesn't find.

Subject: Find doesn't find.

From: Aino

Date: 10 Aug, 2010 14:07:05

Message: 1 of 4

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

Subject: Find doesn't find.

From: dpb

Date: 10 Aug, 2010 14:07:58

Message: 2 of 4

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>


--

Subject: Find doesn't find.

From: Sean

Date: 10 Aug, 2010 14:13:04

Message: 3 of 4

"Aino" <aino.tietavainen@removeThis.helsinki.fi> wrote in message <i3rme9$12$1@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

Subject: Find doesn't find.

From: Aino

Date: 10 Aug, 2010 14:54:05

Message: 4 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i3rmpg$m4m$1@fred.mathworks.com>...
> "Aino" <aino.tietavainen@removeThis.helsinki.fi> wrote in message <i3rme9$12$1@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us