repeat a matrix as digonal element in a new matrix?

Hi
I have a 2D matrix, and I want repeat it a digonal element in a new matrix., somthing like this:
A is 2*3 matrix , and we want reapeat for 10 time like:
B= [ A 0 0 .....0; 0 A 0 .....0; .............. ;0 0 0 ........A]
hence B is a 20*30 matrix. How can make B without using "for"?

 採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 5 月 30 日

9 投票

Hi,
I usually use blkdiag:
A = rand(2,3);
ACell = repmat({A}, 1, 10);
BigA = blkdiag(ACell{:});
Titus

3 件のコメント

smabtahi
smabtahi 2012 年 5 月 30 日
Thanks a lot Titus.
This apprich is working very fast for large matrixes.
CLOUDY LU
CLOUDY LU 2020 年 3 月 8 日
Very useful! Thanks a lot.
Dr. Muhammad Fiaz
Dr. Muhammad Fiaz 2022 年 1 月 24 日
Thank you sir.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 30 日

1 投票

blkdiag() or possibly kron()

1 件のコメント

Qingyu
Qingyu 2016 年 6 月 29 日
編集済み: Qingyu 2016 年 6 月 29 日
Thank you.

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by