repeat a matrix as digonal element in a new matrix?

4 vues (au cours des 30 derniers jours)
smabtahi
smabtahi le 30 Mai 2012
Commenté : Muhammad Fiaz le 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"?

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 30 Mai 2012
blkdiag() or possibly kron()
  1 commentaire
Qingyu
Qingyu le 29 Juin 2016
Modifié(e) : Qingyu le 29 Juin 2016
Thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by