Update matrix from matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
M1 =
1 --> Position 1
2 --> Position 2
1 --> Position 3
2 --> Position 4
M2 =
2 1 3 4
Hi All,
I need your help in coding for a simple program.
I have two Matrices (or Arrays) and I want to update M2 according to M1.
This i tell you how, for instance, whatever number is present in M1 third position gets updated in every index of M2 where number 3 is present. And same goes for all positions of M2.
So, my desired result would be like this {M2 = 2 1 1 2 }
Please help.
0 commentaires
Réponses (1)
Tasneem
le 12 Juil 2022
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);
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!