MATLAB: Replacing row values from another matrix

matrix row

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

Best Answer

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