repeat a matrix as digonal element in a new matrix?

8 ビュー (過去 30 日間)
smabtahi
smabtahi 2012 年 5 月 30 日
コメント済み: Muhammad Fiaz 2022 年 1 月 24 日
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 日
Hi,
I usually use blkdiag:
A = rand(2,3);
ACell = repmat({A}, 1, 10);
BigA = blkdiag(ACell{:});
Titus
  3 件のコメント
CLOUDY LU
CLOUDY LU 2020 年 3 月 8 日
Very useful! Thanks a lot.
Muhammad Fiaz
Muhammad Fiaz 2022 年 1 月 24 日
Thank you sir.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 30 日
blkdiag() or possibly kron()
  1 件のコメント
Qingyu
Qingyu 2016 年 6 月 29 日
編集済み: Qingyu 2016 年 6 月 29 日
Thank you.

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

カテゴリ

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