how to block diagonalize a 3D matrix

how to blkdiag a 3D matrix. The blkdiag operation is done to 2D slice along dim 3

回答 (1 件)

Teja Muppirala
Teja Muppirala 2013 年 1 月 11 日

0 投票

R = rand(4,2,3);
M = mat2cell(R,4,2,ones(1,size(R,3)));
M = blkdiag(M{:})

1 件のコメント

Timothy
Timothy 2016 年 1 月 26 日
Hmm. Make that third dimension a lot bigger.
R = rand(4,2,65341); tic M = mat2cell(R, 4,2,ones(1, size(R,3))); toc
Elapsed time is 6.065165 seconds.
I was hoping to use blkdiag to perform a [3x2] * [2 x 1] calculation a whole bunch of times, P = 65341 times. For looping through takes 2.5s. Setting up the block diagonal in this way is much slower. Is there a faster way?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

質問済み:

Yue
2013 年 1 月 11 日

コメント済み:

2016 年 1 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by