repeat a matrix as digonal element in a new matrix?

4 Ansichten (letzte 30 Tage)
smabtahi
smabtahi am 30 Mai 2012
Kommentiert: Muhammad Fiaz am 24 Jan. 2022
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"?

Akzeptierte Antwort

Titus Edelhofer
Titus Edelhofer am 30 Mai 2012
Hi,
I usually use blkdiag:
A = rand(2,3);
ACell = repmat({A}, 1, 10);
BigA = blkdiag(ACell{:});
Titus
  3 Kommentare
CLOUDY LU
CLOUDY LU am 8 Mär. 2020
Very useful! Thanks a lot.
Muhammad Fiaz
Muhammad Fiaz am 24 Jan. 2022
Thank you sir.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 30 Mai 2012
blkdiag() or possibly kron()

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by