Replacing row values from another matrix
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sule Tekkesinoglu
il 19 Apr 2020
Modificato: Ameer Hamza
il 19 Apr 2020
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
0 Commenti
Risposta accettata
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
0 Commenti
Più risposte (0)
Vedere anche
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!