Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: ismember - getting wrong result
Date: Thu, 12 Mar 2009 13:12:02 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 31
Message-ID: <gpb1n2$851$1@fred.mathworks.com>
References: <gpb180$5uv$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236863522 8353 172.30.248.35 (12 Mar 2009 13:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Mar 2009 13:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:524310


"Ashwini Deshpande"
> I have a matrix as follows,
> a = 0:0.1:1;
> when i tried to find whether 0.300 is present in the matrix 'a', using following procedure, 
> >> [tf, loc]=ismember(0.3,a)
> i got the following result...

you get the CORRECT result, of course...

% look what happens
     v=0:.1:1;
     n=0.3;
     sprintf('%30.20f\n',v(4),n)
%{
     0.30000000000000004000 % <- result from vec
     0.29999999999999999000 % <- result from handwritten number
%}
     format hex;
     [v(4),n,v(4)-n].'
%{
     3fd3333333333334 % <- vec
     3fd3333333333333 % <- num
     3c90000000000000 % <- diff
%}
     format;

% also, peruse     

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

us