How can I find out the diagonal elements of any matrics? Again i want to arrange it in row by row

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];

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2013년 3월 20일
편집: Andrei Bobrov 2013년 3월 20일
b = spdiags(a).';
general case
b = spdiags(a,-size(a,1)+1:size(a,2)-1).';

이 질문은 마감되었습니다.

태그

질문:

2013년 3월 20일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by