It is my understanding that you have two Arrays M1 & M2. M2 contains indexes and you want to update M2 according to the values present at those indexes in M1.
The MATLAB code for this is given below and this code is giving the desired result.
m1 = [1,2,1,2];
m2 = [2,1,3,4];
m2(1:length(m2)) = m1(m2);