Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


dpb
Posts:
9,840
Registered:
6/7/07


Re: Replacing `find` with logical indexing
Posted:
Jul 9, 2013 11:29 PM


On 7/9/2013 9:24 PM, TideMan wrote: > On Wednesday, July 10, 2013 1:20:34 PM UTC+12, dpb wrote: ...
>>> ... How do I use logical indexing to fix this?
>>> nonZeroD = abs(D(find(D)));
>> nonZeroD = abs(D(D~0)); >> ...
>> I'm not absolutely positive I follow what you're trying to do but why >> isn't it just >> >> DNZmin=min(abs(D(D~0))); % ? >> >> What's the point of the max(DNZ(DNZ==min(DNZ)))? If you've only >> collected terms in the vector ==min(vector), then the max is the min by >> that selection process. >> ...
> Oh dpb, what a dreadful typist you are....... > It should be ~=, not ~: > DNZmin=min(abs(D(D~=0)));
Indeed, my typing has gotten worse and worse... :( Doesn't help that my eyes are as well so the differences between = and  and { and (, etc., aren't so obvious as once were...
> And with floating point numbers, shouldn't it be: > DNZmin=min(abs(D(abs(D)>tol))); > where tol is a small number like 1e6
Actually, I started to write about that one, but in this case it's not a problem since the comparison is to the min() of the values in the same vector. It's the same value identically being compared to.
If in the original code the lambda in the comparison were some other fp value, then your recommendation/concern is right on. But in the actual code lambda is min() of of the same vector so it's identical by that process of selection already and the existence of a value off by only LSB in the mantissa if it were to exist is already out, anyway. But the missed comparison of a value entered at the keyboard trying to compare to one computed internally as is so often the cause of the FAQ question doesn't arise here.




