M1 =
1 --> Position 1
2 --> Position 2
1 --> Position 3
2 --> Position 4
M2 =
2 1 3 4
I need help in coding for a simple program. I have two matrices (or arrays, samples given above) and I want to update M2 according to M1.
For instance, whatever number is present in M1 third position gets updated in every index of M2 where number 3 is present. And the same goes for all positions of M2.
So, my desired result would be like this: M2 = [2 1 1 2]
How can I accomplish this?