MATLAB: Find index of a matrix of values into another matrix

findindex

Hello,
I have a matrix A 151×1 double and a matrix B 151×1000 double. Each value of A corresponds to a certain value in the same row of B. For example if A=22;14;53;2, then B will have the value 22 in one of its columns in the first row, the value 14 in one of its columns in the second row etc. Is there a way to have the matrix of the index of all the columns in B that contain the values of A (always in their coresponding row?).

Best Answer

Indices = cell(numel(A),1);
for k = 1:numel(A)
Indices{k} = find(B(k,:)==A(k));
end
%celldisp(Indices)
% Indices{1} represents first element of A match in first row of B likewise others