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:
Why "find" function doesn't work with decimal values???!!!!!

Subject: Why "find" function doesn't work with decimal values???!!!!!

From: Camille Couzi

Date: 17 Feb, 2011 19:36:03

Message: 1 of 3

Hi, I just discovered a very very odd thing: "find" doesn't find anything when searching decimal values!!!!!!
example:

a=linspace(0.01,0.49,49);
ind=find(a==0.18)

answer of matlab:
ans =

   Empty matrix: 1-by-0

when, a(18)==0.18!!!!

what's the problem???
when defining a=linspace(1,49,49) (integer numbers), it works!!!

Subject: Why "find" function doesn't work with decimal values???!!!!!

From: Sean de

Date: 17 Feb, 2011 19:48:03

Message: 2 of 3

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <ijjtb3$2e7$1@fred.mathworks.com>...
> Hi, I just discovered a very very odd thing: "find" doesn't find anything when searching decimal values!!!!!!
> example:
>
> a=linspace(0.01,0.49,49);
> ind=find(a==0.18)
>
> answer of matlab:
> ans =
>
> Empty matrix: 1-by-0
>
> when, a(18)==0.18!!!!
>
> what's the problem???
> when defining a=linspace(1,49,49) (integer numbers), it works!!!

http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Subject: Why "find" function doesn't work with decimal values???!!!!!

From: Matt J

Date: 17 Feb, 2011 20:38:03

Message: 3 of 3

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <ijjtb3$2e7$1@fred.mathworks.com>...
>
> answer of matlab:
> ans =
>
> Empty matrix: 1-by-0
>
> when, a(18)==0.18!!!!
=============

Ah, but did you really check that a(18)==0.18 is true? It appears not:

>> a=linspace(0.01,0.49,49);
>> a(18)==.18

ans =

     0

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