Converting each cell of an array to one block diagonal matrix

7 ビュー (過去 30 日間)
Vishnu Kant
Vishnu Kant 2018 年 9 月 9 日
回答済み: Ilias Misailidis 2020 年 6 月 11 日
I have a cell array where each cell contains different size of square adjacency matrix for example
A = 29x29 double
30x30 double
24x24 double
10x10 double
Now I want to create One Block diagonal matrix B from each cell of A such that each cell Of A is in the diagonal in B. Example
B = [29X29] 0 0 0 0 0 0 0 0 0 0
0 0 [30x30] 0 0 0 0 0 0 0
0 0 0 0 [24X24] 0 0 0
0 0 0 0 0 0 [10x10]
so B would NxN where N = 29+30+24+10
I tried with the following code but it did not work.
function B =blockD(A)
n=size(A,1);
for i = 1:n
B=blkdiag(A{i});
end
end
Also at the end I have to row normalised matrix B

採用された回答

Matt J
Matt J 2018 年 9 月 9 日
B=blkdiag(A{:});

その他の回答 (1 件)

Ilias Misailidis
Ilias Misailidis 2020 年 6 月 11 日
Hi my name is Ilias and i am new entry to Matlab. I am trying to make a block matrix 9x9 like foto for my homework to university and nothing happened with code.
Someone to help me :-)

カテゴリ

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