How to copy anti diagonal elements to another matrix?
Show older comments
Accepted Answer
More Answers (2)
If A is your matrix. To get anti diagonal elements use:
diag(fliplr(A))
To get diagonal elements use:
diag(A)
Andrei Bobrov
on 3 Nov 2017
Edited: Andrei Bobrov
on 3 Nov 2017
A = randi(127,7)
B = randi(127,7)
s = size(A);
lo = eye(s) + flip(eye(s),2) > 0;
B(lo) = A(lo);
Categories
Find more on Operating on Diagonal Matrices 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!