The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Replacing `find` with logical indexing
Replies: 6   Last Post: Jul 10, 2013 1:47 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 113
Registered: 11/22/09
Replacing `find` with logical indexing
Posted: Jul 9, 2013 8:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am trying to find the smallest nonzero magnitude element of a vector, D. Note that D is not integers. I am eliminating nonzero entries using the `find` command (first line below). The editor says to replace `find` with logical indexing, but replacing `D(find(D))` with `D(D)` returns an error. This is not slowing my code very much, but the editor's warning is mildly bothersome. How do I use logical indexing to fix this?

nonZeroD = abs(D(find(D)));
lambda = max(nonZeroD(nonZeroD == min(nonZeroD)));
ICmode = find(D==lambda, 1, 'first');

I also note that the editor doesn't complain about the second `find`.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.