I am trying to find the indices of elements in a vector that correspond to another vector, preferably without using loops. For example, my input might be:
DJiSet = [5 7 8]; % elements of which I need the indices
JiSet = [3 4 5 6 7 8 9 11 12 20]; % vector to search
The output here would be:
[3 5 6]
The fastest I've come up with so far is this:
Output = find(ismember(JiSet,DJiSet));
However I have a feeling this could be done faster, especially since I thought the find
command is rather slow.
Things to note:
- The values in
DJiSet
are guaranteed to all be present in JiSet
JiSet
is always sorted in ascending order, without repeated entries
- The vector
DJiSet
is not guaranteed to be found contiguously in JiSet
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…