MATLAB: Finding index of long vector elements in another short vector

findintersectismemebr

Hi,
Now I have a problem to find a easy and efficient way to find index of longer vector in another short vector.
Say, we have A = [1 3 2]; B = [1 2 1 3 2] ; I want C = BindexInA = [1 3 1 2 3] ;
  1. intersect ( ) omits repeated values;
  2. C = arrayfun(@(x)find(A==x,1),B) takes much time;
Is there any easy but efficient way to do this? Thanks in advance.

Best Answer

doc ismemebr
A = [1 3 2]; B = [1 2 1 3 2] ;
[val,idx] = ismember(B,A) ;
idx
Related Question