From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 'find' returns non-integer indices (potential bug?)
Date: Tue, 30 Dec 2008 10:53:04 -0500
Organization: The MathWorks, Inc.
Lines: 52
Message-ID: <gjdg50$st3$>
References: <gjd87p$q3m$> <>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: 1230652384 29603 (30 Dec 2008 15:53:04 GMT)
NNTP-Posting-Date: Tue, 30 Dec 2008 15:53:04 +0000 (UTC)
User-Agent: Thunderbird (Windows/20081105)
In-Reply-To: <HIDDEN>
Xref: comp.soft-sys.matlab:509234

Rune Allnor wrote:
> On 30 Des, 14:38, "Tamar Friedlander" <>
> wrote:
>> After extensive use in a simiulation, it occurs once in a while that 'find' returns non-integer indices! (happened in Matlab 7.5.0)
> Do you have an example where this happens?
>> Typing the index in a long format I received something like: 61,143.000001. Trying to round the indices didn't help either.
>> This happens at different timings and seems unrelated to the simulation code, and is unreproducible if the very same code line is retyped.
>> Is it a bug or could I be misusing 'find'?
>> Does anyone know how to avoid it (except for re-writing the code which will not use 'find')?
> This is likely a consequence of matlab not being a typed language.

MATLAB is a dynamically typed language.

> Everything is represented as double-precision floating point numbers.

That hasn't been true for more than ten years.

> Integers are represented as floats to within numerical precision.

Although that's no longer always true, it is accurate with respect to 
the output of find, which does return double-precision floats.  However, 
there is no floating-point arithmetic going on in the internal code.  If 
find really is returning a noninteger value, it's a plain ol' bug having 
nothing whatever to do with types, floating-point, etc.

However, I do not usually start out by assuming a trouble report is 
really a bug, especially in this case, where I haven't yet seen a line 
of code.  So I don't really know how find has been called, and if 
anything else might have operated on the output from find between the 
call and when the output was displayed.  For all we know from the 
information posted so far, the root cause could be a user-written 
MEX-file that has corrupted MATLAB's internal data structures.  Or maybe 
earlier code has actually assigned a value to a variable called "find", 
so that later code is actually indexing into that variable instead of 
calling the function "find".  Either of those explanations strike me as 
more likely than an actual bug in find.

To the original poster, Tamar, I suggest setting a conditional 
breakpoint on the line containing the call to find, so that the debugger 
will stop there if any of the output values are nonempty.  You might be 
able to find a reproducible test case that way.  Oh, and double-check 
that you aren't using "find" as a variable name somewhere.

Steve Eddins