Effacer les filtres
Effacer les filtres

Creating a matrix whose entries are matrix

1 vue (au cours des 30 derniers jours)
Ali Baig
Ali Baig le 25 Mai 2018
Modifié(e) : Ali Baig le 25 Mai 2018
Given a matrix
A = [-4 1 0; 1 -4 1; 0 1 -4];
I want to create a matrix B such that
B = [A I 0; I B I; 0 I B];
where I is identity matrix whose size is equal to size of A. How can I do this?

Réponse acceptée

Stephen23
Stephen23 le 25 Mai 2018
Modifié(e) : Stephen23 le 25 Mai 2018
>> A = [-4 1 0; 1 -4 1; 0 1 -4];
>> I = eye(size(A));
>> Z = zeros(size(A));
>> B = [A I Z; I A I; Z I A]
B =
-4 1 0 1 0 0 0 0 0
1 -4 1 0 1 0 0 0 0
0 1 -4 0 0 1 0 0 0
1 0 0 -4 1 0 1 0 0
0 1 0 1 -4 1 0 1 0
0 0 1 0 1 -4 0 0 1
0 0 0 1 0 0 -4 1 0
0 0 0 0 1 0 1 -4 1
0 0 0 0 0 1 0 1 -4
Although perhaps what you want is toeplitz ?:
  1 commentaire
Ali Baig
Ali Baig le 25 Mai 2018
Modifié(e) : Ali Baig le 25 Mai 2018
Thank you Stephen. I will look into the details of toeplitz.

Connectez-vous pour commenter.

Plus de réponses (1)

Ameer Hamza
Ameer Hamza le 25 Mai 2018
I am assuming the in your question, you wrote B by mistake on the Left side of the 2nds statement and they are actually matrix A. If you want to create a big matrix B then follow @Stephen's answer. But If you want them to remain as separate matrices, then you will need a cell array
B = {A I Z; I A I; Z I A};
B =
3×3 cell array
{3×3 double} {3×3 double} {3×3 double}
{3×3 double} {3×3 double} {3×3 double}
{3×3 double} {3×3 double} {3×3 double}
Access each matrix using curly bracket notation. B{1, 2} will access matrix in the first row and second column.

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by