Replacing row values from another matrix

2 visualizaciones (últimos 30 días)
Sule Tekkesinoglu
Sule Tekkesinoglu el 19 de Abr. de 2020
Editada: Ameer Hamza el 19 de Abr. de 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

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 19 de Abr. de 2020
Editada: Ameer Hamza el 19 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by