Replacing row values from another matrix
2 views (last 30 days)
Show older comments
Sule Tekkesinoglu
on 19 Apr 2020
Edited: Ameer Hamza
on 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 Comments
Accepted Answer
Ameer Hamza
on 19 Apr 2020
Edited: Ameer Hamza
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!