How can I make a matrix with diagonals composed of matrices?

1 回表示 (過去 30 日間)
Sebastian
Sebastian 2014 年 10 月 3 日
編集済み: Matt J 2014 年 10 月 3 日
See attached image. A is a 2x2 and B is a 2x1 (although it would be nice to generalize).
Any suggestions on how to easily create this matrix? I know I could use a for loop, but is there some easier way using matlab functions?

回答 (2 件)

Matt J
Matt J 2014 年 10 月 3 日
編集済み: Matt J 2014 年 10 月 3 日
I don't think you can or should avoid a for-loop, but there are ways to use looping more economically,
C=cell(1,N+1);
C{1}=zeros(size(B));
C{2}=B;
for i=3:N+1
C{i}=A*C{i-1};
end
idx=toeplitz(1:N+1,ones(1,N+1));
result=cell2mat( C(idx) )

Star Strider
Star Strider 2014 年 10 月 3 日
The blkdiag function is your friend here. It was intended for just this purpose.

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by