Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <gjd87p$q3m$1@fred.mathworks.com> <MPG.23c40a995544ece0989912@news.mathworks.com> <gjdgg6$kme$1@fred.mathworks.com> <gje8km$437$1@fred.mathworks.com> <gjfpvd$amc$1@fred.mathworks.com> <gjgbhu$hqd$1@fred.mathworks.com> <gji1s2$c1i$1@fred.mathworks.com> <gjir7t$ctl$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 1230831421 15719 172.30.248.38 (1 Jan 2009 17:37:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Jan 2009 17:37:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1653751
Xref: news.mathworks.com comp.soft-sys.matlab:509425

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gjir7t$ctl$1@fred.mathworks.com>...
> "Tamar Friedlander" <tammy_in_the_andes@yahoo.com> wrote in message <gji1s2$c1i$1@fred.mathworks.com>...
> > 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 !!!')
end;

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,
Tamar.