MATLAB: Hello guys, I am trying to use the find function to get the position of the elements of an array from another vector. There are matching elements from the array in the vector and i need to have in an array the elements position in the vector.

findfor loopindexindexing

a = ones(size(md_27)); %md_27 is 27x141
r = 27;
c = 141;
%here i need to find the position of md_27(i,j) element in vector mp_d_27 and return it in a(i,j)
for i = 1:r
for i = 1:c
a(i,j) = find(md_27(i,j) = mp_d_27) %mp_d_27 is 1767x1
end
end

Best Answer

[tf, a] = ismember(md_27, mp_d_27);
Now tf(i,j) is true if md_27(i,j) was found in mp_d_27, and if so then a(i,j) is the index into mp_d_27