Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Logical error
Date: Thu, 22 Oct 2009 15:41:21 +0000 (UTC)
Organization: Xoran Technologies
Lines: 19
Message-ID: <hbpuf1$hn3$1@fred.mathworks.com>
References: <hbprfe$lvf$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1256226081 18147 172.30.248.38 (22 Oct 2009 15:41:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 22 Oct 2009 15:41:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:579361


"Andrew " <apkelley@princeton.edu> wrote in message <hbprfe$lvf$1@fred.mathworks.com>...
> I am getting a logical error with the following code which I don't understand and would appreciate any help figuring out:
> 
> >> n=0.6:0.05:2.0;
> >> any(n==1.2)
> 
> ans =
> 
>      0
> 
> >> any(n==1.0)
> 
> ans =
> 
>      1
> 
> I can check all of the values in n and only the value of 1.2 returns false.  I would appreciate any help figuring this one out.  Thanks.  

FAQ. The values of of n are not exact, because there are floating point errors in generating them.  It's pure luck that any of them return the expected result.