koolguyuf <tdgoswami@gmail.com> wrote in message <bf28c7fc-
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com>...
> Hi,
>
> I am facing some weird behavior using the find function in
matlab
> versions 7.0 and 7.5 . I have this extremely simple code
to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ?
Suprisingly, I
> am not able to get it.
>
> Plz help.
>
> Thanks
> TD
That's right.
The first command will create a vector a
a = [0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0]
The second line returns my_index = 4 because a(4) = 0.6.
Anh Huy Phan
RIKEN - BSI
Subject: Re: problem with the find function in matlab
koolguyuf <tdgoswami@gmail.com> wrote in message <bf28c7fc-
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com>...
> Hi,
>
> I am facing some weird behavior using the find function in
matlab
> versions 7.0 and 7.5 . I have this extremely simple code
to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ?
Suprisingly, I
> am not able to get it.
>
> Plz help.
>
> Thanks
> TD
That's right.
The first command will create a vector a
a = [0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0]
The second line returns my_index = 4 because a(4) = 0.6.
Anh Huy Phan
RIKEN - BSI
Subject: Re: problem with the find function in matlab
koolguyuf wrote:
> Hi,
>
> I am facing some weird behavior using the find function in matlab
> versions 7.0 and 7.5 . I have this extremely simple code to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ? Suprisingly, I
> am not able to get it.
W/ R12 it returns 4.
What does it return for you?
What platform?
If not 4, one would have to presume there's an issue of exact matching
for the particular combination of OS/version/hardware.
To get to the bottom of behavior, need above information at least.
Executing the lines and pasting results could be useful as could
a = [0:0.2:2];
b = a - 0.6
just possibly be educational...
--
Subject: Re: problem with the find function in matlab
koolguyuf <tdgoswami@gmail.com> wrote in message <bf28c7fc-
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com>...
> Hi,
>
> I am facing some weird behavior using the find function in matlab
> versions 7.0 and 7.5 . I have this extremely simple code to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ? Suprisingly, I
> am not able to get it.
>
> Plz help.
>
> Thanks
> TD
---------
The problem is not with the 'find' command but with the floating point
representation of 0.2 in a. The n-th term in a vector expression, [p:d:q],
should ideally be p+(n-1)*d. However, the difficulty is that this latter
computation may experience round-off errors due to the imprecision of the
computer's representation of such a d. After all, it is using binary not
decimal floating point numbers. Using format hex with your example we get
0+(4-1)*.2 = 3fe3333333333334
whereas the most accurate representation of .6 is actually
.6 = 3fe3333333333333
which is just slightly different in the least bit (as Shaun has also pointed out.)
When you write find(a==.6), the find command requires exact equality of
both sides of the equation and would therefore not pick up the fourth index.
MathWorks uses various schemes in computing progressions of the form
[p:d:q] to avoid some of these eccentric results, but it is unlikely they are able
to avoid all of them. If you have a value of d which has an exact expression
in decimal but not in binary, it is likely that a long enough sequence will
encounter cases that would be missed by a 'find' scan, even in their latest
matlab versions.
Roger Stafford
Subject: Re: problem with the find function in matlab
koolguyuf <tdgoswami@gmail.com> wrote in message <bf28c7fc-
c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com>...
> Hi,
>
> I am facing some weird behavior using the find function
in matlab
> versions 7.0 and 7.5 . I have this extremely simple code
to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ?
Suprisingly, I
> am not able to get it.
>
> Plz help.
>
> Thanks
> TD
Hi,
Im also experiencing the same problem. But when I
entered 'a' manually (i.e. a = [0 0.1 0.2 0.4 0.6 ... 2])
I get the correct answer.
Subject: Re: problem with the find function in matlab
"Jerecho " <jeric3182@mathworks.com> wrote in message <flpgo6$ouf
$1@fred.mathworks.com>...
> Im also experiencing the same problem. But when I
> entered 'a' manually (i.e. a = [0 0.1 0.2 0.4 0.6 ... 2])
> I get the correct answer.
-------
That should tell you what the trouble is, Jerecho. It's not the fault of 'find'. It's
because 0:.2:2 generates a slightly different vector of values than [0,.2,.4,.6,
etc]. And that in turn is because it does not have an exact value of .2 to work
with. It cannot achieve .2 precisely and any calculations with it are bound to go
slightly wrong at some stage.
Roger Stafford
Subject: Re: problem with the find function in matlab
"koolguyuf" <tdgoswami@gmail.com> wrote in message
news:bf28c7fc-c160-40da-ac3b-0e7b48b025b1@v46g2000hsv.googlegroups.com...
> Hi,
>
> I am facing some weird behavior using the find function in matlab
> versions 7.0 and 7.5 . I have this extremely simple code to execute.
>
> a = [0:0.2:2];
> my_index = find(a == 0.6)
>
> plz let me know whether you are getting my_index = 4 ? Suprisingly, I
> am not able to get it.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.