Diagonal matrix from multiple columns of an array

1 回表示 (過去 30 日間)
Saeid
Saeid 2018 年 11 月 4 日
回答済み: Bruno Luong 2018 年 11 月 4 日
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?

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 4 日
Take a look at spdiags

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by