Azzera filtri
Azzera filtri

Update matrix from matrix

1 visualizzazione (ultimi 30 giorni)
Gavanpreet Singh Bhatia
Gavanpreet Singh Bhatia il 30 Gen 2018
Risposto: Tasneem il 12 Lug 2022
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.

Risposte (1)

Tasneem
Tasneem il 12 Lug 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);

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by