<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579</link>
    <title>MATLAB Central Newsreader - problem with the find function in matlab</title>
    <description>Feed for thread: problem with the find function in matlab</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 07 Jan 2008 00:43:51 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408250</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
"koolguyuf" &amp;lt;tdgoswami@gmail.com&amp;gt; wrote in message &lt;br&gt;
news:bf28c7fc-c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function in matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code to execute.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&lt;br&gt;
This is a very frequently asked question.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://matlabwiki.mathworks.com/MATLAB_FAQ"&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Question 6.1 talks about this type of behavior.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 06 Jan 2008 03:46:36 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408183</link>
      <author>Roger Stafford</author>
      <description>"Jerecho " &amp;lt;jeric3182@mathworks.com&amp;gt; wrote in message &amp;lt;flpgo6$ouf&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Im also experiencing the same problem. But when I &lt;br&gt;
&amp;gt; entered 'a' manually (i.e. a = [0 0.1 0.2 0.4 0.6 ... 2])&lt;br&gt;
&amp;gt; I get the correct answer.&lt;br&gt;
-------&lt;br&gt;
That should tell you what the trouble is, Jerecho.  It's not the fault of 'find'.  It's &lt;br&gt;
because 0:.2:2 generates a slightly different vector of values than [0,.2,.4,.6, &lt;br&gt;
etc].  And that in turn is because it does not have an exact value of .2 to work &lt;br&gt;
with.  It cannot achieve .2 precisely and any calculations with it are bound to go &lt;br&gt;
slightly wrong at some stage.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 06 Jan 2008 03:08:54 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408181</link>
      <author>Jerecho </author>
      <description>koolguyuf &amp;lt;tdgoswami@gmail.com&amp;gt; wrote in message &amp;lt;bf28c7fc-&lt;br&gt;
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function &lt;br&gt;
in matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code &lt;br&gt;
to execute.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? &lt;br&gt;
Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Plz help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; TD&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
&lt;br&gt;
Im also experiencing the same problem. But when I &lt;br&gt;
entered 'a' manually (i.e. a = [0 0.1 0.2 0.4 0.6 ... 2])&lt;br&gt;
I get the correct answer.&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 20:52:05 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408171</link>
      <author>Roger Stafford</author>
      <description>koolguyuf &amp;lt;tdgoswami@gmail.com&amp;gt; wrote in message &amp;lt;bf28c7fc-&lt;br&gt;
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function in matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code to execute.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Plz help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; TD&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;The problem is not with the 'find' command but with the floating point &lt;br&gt;
representation of 0.2 in a.  The n-th term in a vector expression, [p:d:q], &lt;br&gt;
should ideally be p+(n-1)*d.  However, the difficulty is that this latter &lt;br&gt;
computation may experience round-off errors due to the imprecision of the &lt;br&gt;
computer's representation of such a d.  After all, it is using binary not &lt;br&gt;
decimal floating point numbers.  Using format hex with your example we get&lt;br&gt;
&lt;br&gt;
&amp;nbsp;0+(4-1)*.2 = 3fe3333333333334&lt;br&gt;
&lt;br&gt;
whereas the most accurate representation of .6 is actually&lt;br&gt;
&lt;br&gt;
&amp;nbsp;.6 = 3fe3333333333333&lt;br&gt;
&lt;br&gt;
which is just slightly different in the least bit (as Shaun has also pointed out.)  &lt;br&gt;
When you write find(a==.6), the find command requires exact equality of &lt;br&gt;
both sides of the equation and would therefore not pick up the fourth index.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;MathWorks uses various schemes in computing progressions of the form&lt;br&gt;
[p:d:q] to avoid some of these eccentric results, but it is unlikely they are able &lt;br&gt;
to avoid all of them.  If you have a value of d which has an exact expression &lt;br&gt;
in decimal but not in binary, it is likely that a long enough sequence will &lt;br&gt;
encounter cases that would be missed by a 'find' scan, even in their latest &lt;br&gt;
matlab versions.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 16:23:02 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408156</link>
      <author>dpb</author>
      <description>koolguyuf wrote:&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function in matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code to execute.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&lt;br&gt;
W/ R12 it returns 4.&lt;br&gt;
&lt;br&gt;
What does it return for you?&lt;br&gt;
&lt;br&gt;
What platform?&lt;br&gt;
&lt;br&gt;
If not 4, one would have to presume there's an issue of exact matching &lt;br&gt;
for the particular combination of OS/version/hardware.&lt;br&gt;
&lt;br&gt;
To get to the bottom of behavior, need above information at least. &lt;br&gt;
Executing the lines and pasting results could be useful as could&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;a = [0:0.2:2];&lt;br&gt;
&amp;nbsp;&amp;nbsp;b = a - 0.6&lt;br&gt;
&lt;br&gt;
just possibly be educational...&lt;br&gt;
&lt;br&gt;
--&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 16:11:12 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408153</link>
      <author>Huy </author>
      <description>koolguyuf &amp;lt;tdgoswami@gmail.com&amp;gt; wrote in message &amp;lt;bf28c7fc-&lt;br&gt;
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function in &lt;br&gt;
matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code &lt;br&gt;
to execute.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? &lt;br&gt;
Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Plz help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; TD&lt;br&gt;
&lt;br&gt;
That's right.&lt;br&gt;
&lt;br&gt;
The first command will create a vector a &lt;br&gt;
&lt;br&gt;
a = [0 0.2 0.4 0.6 0.8  1.0  1.2  1.4  1.6 1.8 2.0]&lt;br&gt;
&lt;br&gt;
The second line returns my_index = 4 because a(4) = 0.6.&lt;br&gt;
&lt;br&gt;
Anh Huy Phan&lt;br&gt;
RIKEN - BSI&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 16:05:59 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408152</link>
      <author>Shaun</author>
      <description>&amp;gt;&amp;gt; format hex&lt;br&gt;
&amp;gt;&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt;&amp;gt; a(4)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3fe3333333333334&lt;br&gt;
&amp;gt;&amp;gt; 0.6&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3fe3333333333333&lt;br&gt;
&lt;br&gt;
Look into floating point numbers. There are several posts&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 16:05:18 -0500</pubDate>
      <title>Re: problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408151</link>
      <author>Huy </author>
      <description>koolguyuf &amp;lt;tdgoswami@gmail.com&amp;gt; wrote in message &amp;lt;bf28c7fc-&lt;br&gt;
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am facing some weird behavior using the find function in &lt;br&gt;
matlab&lt;br&gt;
&amp;gt; versions 7.0 and 7.5 . I have this extremely simple code &lt;br&gt;
to execute.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; a = [0:0.2:2];&lt;br&gt;
&amp;gt; my_index = find(a == 0.6)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plz let me know whether you are getting my_index = 4 ? &lt;br&gt;
Suprisingly, I&lt;br&gt;
&amp;gt; am not able to get it.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Plz help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&amp;gt; TD&lt;br&gt;
&lt;br&gt;
That's right.&lt;br&gt;
&lt;br&gt;
The first command will create a vector a &lt;br&gt;
&lt;br&gt;
a = [0 0.2 0.4 0.6 0.8  1.0  1.2  1.4  1.6 1.8 2.0]&lt;br&gt;
&lt;br&gt;
The second line returns my_index = 4 because a(4) = 0.6.&lt;br&gt;
&lt;br&gt;
Anh Huy Phan&lt;br&gt;
RIKEN - BSI&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 05 Jan 2008 15:54:45 -0500</pubDate>
      <title>problem with the find function in matlab</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161579#408150</link>
      <author>koolguyuf</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I am facing some weird behavior using the find function in matlab&lt;br&gt;
versions 7.0 and 7.5 . I have this extremely simple code to execute.&lt;br&gt;
&lt;br&gt;
a = [0:0.2:2];&lt;br&gt;
my_index = find(a == 0.6)&lt;br&gt;
&lt;br&gt;
plz let me know whether you are getting my_index = 4 ? Suprisingly, I&lt;br&gt;
am not able to get it.&lt;br&gt;
&lt;br&gt;
Plz help.&lt;br&gt;
&lt;br&gt;
Thanks&lt;br&gt;
TD&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
