Replacing row values from another matrix

6 visualizzazioni (ultimi 30 giorni)
Hello, i didnt see if this has been asked but i want to replace the each row from another matrix in same row, but keeping the original row values same in the next iteration. For instance
A=[1 2 3; 4 5 6; 7 8 9] B=[1 1 1; 2 2 2; 3 3 3] and we get C=[1 1 1; 4 5 6; 7 8 9], C=[1 2 3; 2 2 2; 7 8 9], C=[1 2 3; 4 5 6; 3 3 3].
Thanks,
Sule

Risposta accettata

Ameer Hamza
Ameer Hamza il 19 Apr 2020
Modificato: Ameer Hamza il 19 Apr 2020
Try this
A=[1 2 3; 4 5 6; 7 8 9];
B=[1 1 1; 2 2 2; 3 3 3];
for i=1:size(A,1)
C = A;
C(i,:) = B(i,:);
C
end
Result
C =
1 1 1
4 5 6
7 8 9
C =
1 2 3
2 2 2
7 8 9
C =
1 2 3
4 5 6
3 3 3

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB 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