Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Find the location of the single smallest absolute nonzero entry [NO QUESTION HERE]

$
0
0
BTW, as you may have figured out, there is no need to respond to this post. It was posted in error.

"Jeff" wrote in message <kmrfks$raj$1@newscl01ah.mathworks.com>...
> I need to locate the smallest nonzero magnitude entry in a vector. For vectors which don't contain any zeros or any repeated values I use this:
>
> ICmode = find(abs(D)==min(abs(D)));
>
> How do I locate the first smallest entry of the absolute value of vector D? (Note that I need the location in the original D, not the value.)
>
> Before posting this question, it occurred to me I could try
>
> nonZeroD = D(find(D))
>
> But with the zeros stripped out, the indexes of nonZeroD are wrong.
>
> Now I've discovered the 'first' parameter and note that you can use other conditionals in "find". I'm trying
>
> ICmode = find(abs(D)>0, 1, 'first')
>
> But this does not find the smallest entry, just the first nonzero entry. I combine that with my first effort
>
> find((abs(D)>0) && (abs(D)==min(abs(D))), 1, 'first')
>
> But I get an error saying the operands must be logical scalars (and it is logically wrong, anyway - if there is a zero entry, it will not find anything).
>
> Changed && to &.
>
> Trying:
> if ~exist('ICmode','var')
> % ICmode = find(abs(D)==min(abs(D)));
> nonZeroD = D(find(D));
> lambda = nonZeroD(find(abs(nonZeroD)==min(abs(nonZeroD))));
> lambda = max(lambda);
> ICmode = find(D==lambda,1,'first');
> end
> lambda = D(ICmode);

Viewing all articles
Browse latest Browse all 19628

Trending Articles