You want to find all the indices of all elements of A in B? So, some elements of A might occur once, other multiple times, and some not at all. Therefore you need to resort to cell arrays. With arrayfun you can loop over all elements of A:
A = [1 2 3 4]
B = [2 2 1 4 2 1]
C = arrayfun(@(x) find(B==x), A, 'un', 0)
% C{k} now holds the indices into B, where B equals A(k)
Best Answer