Diagonal matrix from multiple columns of an array

2 views (last 30 days)
I have the array
M=[a b c;
d e f;
g h i]
and I want to construct an array composed of several diagonal arrays in the form:
N=[0 a d 0 0;
0 0 b e 0;
0 0 0 c f;
g 0 0 0 0;
0 h 0 0 0]
or basically place the individual columns of M into pre-assigned positions (1 2 -3) in N. How can I do this without a loop?

Accepted Answer

Bruno Luong
Bruno Luong on 4 Nov 2018
Take a look at spdiags

More Answers (0)

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!