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:
ismember problem

Subject: ismember problem

From: dd

Date: 8 Oct, 2010 11:56:03

Message: 1 of 4

Hi,
I've come up recently with this strange 'ismember' trouble.

Say:

DD=[1:0.078:10];
size(DD)
WW=[0:0.001:12];
[dd,ww]=ismember(DD,WW);

In this way, you would expect every single element of 'DD' to be part of 'WW', so that every index in 'dd' should be equal to '1'.
Well this is not the case, as can be seen from:

QQ=find(dd~=0);
size(QQ)

Am I missing something?

Cheers,
dd

Subject: ismember problem

From: Sean

Date: 8 Oct, 2010 12:35:03

Message: 2 of 4

"dd " <samijnsky@hotmail.com> wrote in message <i8n0sj$fed$1@fred.mathworks.com>...
> Hi,
> I've come up recently with this strange 'ismember' trouble.
>
> Say:
>
> DD=[1:0.078:10];
> size(DD)
> WW=[0:0.001:12];
> [dd,ww]=ismember(DD,WW);
>
> In this way, you would expect every single element of 'DD' to be part of 'WW', so that every index in 'dd' should be equal to '1'.
> Well this is not the case, as can be seen from:
>
> QQ=find(dd~=0);
> size(QQ)
>
> Am I missing something?
>
> Cheers,
> dd


Another one succumbs to floating point arithmetic:
http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F

You can get around this with Bruno's ismember:
http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

Subject: ismember problem

From: dpb

Date: 8 Oct, 2010 12:32:09

Message: 3 of 4

dd wrote:
> Hi,
> I've come up recently with this strange 'ismember' trouble.
>
> Say:
>
> DD=[1:0.078:10];
> size(DD)
> WW=[0:0.001:12];
> [dd,ww]=ismember(DD,WW);
>
> In this way, you would expect every single element of 'DD' to be part of
> 'WW', so that every index in 'dd' should be equal to '1'.
> Well this is not the case, as can be seen from:
>
> QQ=find(dd~=0);
> size(QQ)
>
> Am I missing something?
...

Yes, floating point behavior is what you're missing...

See the FAQ wiki ...

<http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F>

--

Subject: ismember problem

From: dd

Date: 8 Oct, 2010 13:04:03

Message: 4 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i8n35n$fqk$1@fred.mathworks.com>...
> "dd " <samijnsky@hotmail.com> wrote in message <i8n0sj$fed$1@fred.mathworks.com>...
> > Hi,
> > I've come up recently with this strange 'ismember' trouble.
> >
> > Say:
> >
> > DD=[1:0.078:10];
> > size(DD)
> > WW=[0:0.001:12];
> > [dd,ww]=ismember(DD,WW);
> >
> > In this way, you would expect every single element of 'DD' to be part of 'WW', so that every index in 'dd' should be equal to '1'.
> > Well this is not the case, as can be seen from:
> >
> > QQ=find(dd~=0);
> > size(QQ)
> >
> > Am I missing something?
> >
> > Cheers,
> > dd
>
>
> Another one succumbs to floating point arithmetic:
> http://matlabwiki.mathworks.com/MATLAB_FAQ#Why_is_0.3-0.2-0.1_not_equal_to_zero_.28or_similar.29.3F
>
> You can get around this with Bruno's ismember:
> http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

OK guys, sorry to bother...
Many thanks for the tip.
dd

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