repeat a matrix as digonal element in a new matrix?

조회 수: 13 (최근 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()

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by