From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 'find' returns non-integer indices (potential bug?)
Date: Thu, 1 Jan 2009 17:37:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 33
Message-ID: <gjiuvt$fb7$>
References: <gjd87p$q3m$> <> <gjdgg6$kme$> <gje8km$437$> <gjfpvd$amc$> <gjgbhu$hqd$> <gji1s2$c1i$> <gjir7t$ctl$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1230831421 15719 (1 Jan 2009 17:37:01 GMT)
NNTP-Posting-Date: Thu, 1 Jan 2009 17:37:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1653751
Xref: comp.soft-sys.matlab:509425

"Roger Stafford" <> wrote in message <gjir7t$ctl$>...
> "Tamar Friedlander" <> wrote in message <gji1s2$c1i$>...
> > N0=500000;
> > S is a vector whose length changes randomly in the simulation and is approximately ~510000.
> > The simulation randomly chooses indices from S and removes them, to make S of length ~500000 again.
> > 
> > Tamar.
>   I think you may have a valid basis for a complaint to Mathworks support, Tamar.  Reduced to its essentials, you are claiming that when matlab's 'find' function is applied to a half-million-long logical vector which contains 98 percent true values, occasionally the returned indices are not all exact integers.  It is very strange that this bug hasn't turned up long before this, so you shouldn't be surprised at a natural reluctance on Mathworks' part to immediately accept this.
>   You also said in your original article, "Trying to round the indices didn't help either."  I find that equally if not more remarkable.  I have never known matlab's 'round' function to fail to return an integer.  Are you very sure of this?  If so, this would be another and quite different bug.  Can you comment further on your statement.  Two such unlikely-sounding bugs occurring together might seem to imply there was something about your particular machine or its settings that was causing the errant performance.
>   One further check I would recommend.  You gave an example of a non-integer, 61143.000001, obtained using 'format long'.  I wish you had done 'format hex' on the number so the individual bits could be deciphered from the hex digit display.  The number is off from the exact integer 61143 down somewhere in the lower 18 bits out of a total of 53.  I wonder what those errant bits are.  I am also quite startled that 'round' is incapable of clearing them away if that is what you are saying.
> Roger Stafford

Regaeding the usage of 'round', in one of my trials to solve the problem I did the following:

dilution = rand (size(S)) > ((length(S) - N0) / length(S));
AA = round (find(dilution));
if sum (mod (AA, 1)) ~=0,
     error ('Non-integer index !!!')

Surprisingly, I still got the same error message after rounding the indices, but I didn't check the 'round' issue any further.

Machine-related (or maybe Matlab version related)? I also suspected there was something about it.
The code was run so far on 3 different machines with different Matlab versions, but the problem appeared only on 2 of them.

Happy new year,