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"?

 Respuesta aceptada

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

3 comentarios

smabtahi
smabtahi el 30 de Mayo de 2012
Thanks a lot Titus.
This apprich is working very fast for large matrixes.
CLOUDY LU
CLOUDY LU el 8 de Mzo. de 2020
Very useful! Thanks a lot.
Thank you sir.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 30 de Mayo de 2012

1 voto

blkdiag() or possibly kron()

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Mayo de 2012

Comentada:

el 24 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by