MATLAB: Hello, I have two matrices of different sizes and I want to find the indices for the elements in the bigger matrix that match with those in the smaller one, allowing for repetition

indicesrepeated positiontwo matrices

Hello, I have two matrices of different sizes and I want to find the indices for the elements in the bigger matrix that match with those in the smaller one, allowing for repetition? A=[1 1 1 2 3 5 5 1 ] B=[1 2 5] I want to get C=[1 2 3 4 6 7 8]

Best Answer

Use ismember():
A=[1 1 1 2 3 5 5 1 ]
B=[1 2 5]
% Want C=[1 2 3 4 6 7 8]
[inA, inB] = ismember(A, B)
C = find(inA)