This is what is described in one of the examples for ismember:
Define two vectors with values in common.
A = [5 3 4 2]; B = [2 4 4
This line will return all indices:
F=arrayfun(@(x)(find(A(x)==B)),1:numel(A),'UniformOutput',false)
Or a longer version, which might be easier to read:
F=cell(numel(A),1);
for x=1:numel(A)
F{x}=find(A(x)==B);
end
find(A(x)==B)
checks for all occurrences of A(x)
in B
. This is done for each element of the array, either using a for loop or arrayfun
.