Azzera filtri
Azzera filtri

Creating a matrix whose entries are matrix

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Stephen23
Stephen23 il 25 Mag 2018
Modificato: Stephen23 il 25 Mag 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 Commento
Ali Baig
Ali Baig il 25 Mag 2018
Modificato: Ali Baig il 25 Mag 2018
Thank you Stephen. I will look into the details of toeplitz.

Accedi per commentare.

Più risposte (1)

Ameer Hamza
Ameer Hamza il 25 Mag 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.

Categorie

Scopri di più su Sparse Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by