Finding indices when vectors is used

1 view (last 30 days)
Mateusz
Mateusz on 20 Feb 2012
Edited: Matt J on 17 Oct 2013
Assume we have x = [1,2,3,1]; If I execute idx = find(x == 1) then idx == [1,4]. Is there similar command for extracting more indices I am interested in, something like find(x == [1,3]) == [1,3,4].
Of course I would like to avoid loops.
-- Ok, but what if we allow repetitions? For instance: find(x == [1,3,1]) == [1,1,3,4,4] Can we do this without using loops?

Accepted Answer

the cyclist
the cyclist on 20 Feb 2012
I think you want the ismember() command.
  2 Comments
Mateusz
Mateusz on 20 Feb 2012
Looks exactly what I am looking for, thanks :)
Mateusz
Mateusz on 20 Feb 2012
Ok, but what if we allow repetitions? For instance: find(x == [1,3,1]) == [1,1,3,4,4] Can we do this without using loops?

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!