repeat a matrix as digonal element in a new matrix?

60 views (last 30 days)
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"?

Accepted Answer

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

More Answers (1)

Walter Roberson
Walter Roberson on 30 May 2012
blkdiag() or possibly kron()

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!