Given two vectors A and B, find the index, idx into A of the element of B so that
A(idx)=B.
Now I know there must be many ways it can be done, but is there a one-liner?
For example if
A=[3 4 5 6 7];B=[6 4 7];
then
[tf,loc]=ismember(A,B);idx=[1:length(A)];idx=idx(tf);idx=idx(loc(tf));disp(A(idx))
will do it but that is four steps. Is there a more elegant way?
Best Answer