How can I find out the diagonal elements of any matrics? Again i want to arrange it in row by row
Info
This question is closed. Reopen it to edit or answer.
Show older comments
suppose i have a matrix as a=[1 2 3 4; 5 6 7 8; 9 10 11 12]; i want the result as b=[0 0 9; 0 5 10; 1 6 11; 2 7 12; 3 8 0; 0 0 4];
Answers (1)
Andrei Bobrov
on 20 Mar 2013
Edited: Andrei Bobrov
on 20 Mar 2013
b = spdiags(a).';
general case
b = spdiags(a,-size(a,1)+1:size(a,2)-1).';
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!