Borrar filtros
Borrar filtros

Creating a matrix whose entries are matrix

1 visualización (últimos 30 días)
Ali Baig
Ali Baig el 25 de Mayo de 2018
Editada: Ali Baig el 25 de Mayo de 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?

Respuesta aceptada

Stephen23
Stephen23 el 25 de Mayo de 2018
Editada: Stephen23 el 25 de Mayo de 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 comentario
Ali Baig
Ali Baig el 25 de Mayo de 2018
Editada: Ali Baig el 25 de Mayo de 2018
Thank you Stephen. I will look into the details of toeplitz.

Iniciar sesión para comentar.

Más respuestas (1)

Ameer Hamza
Ameer Hamza el 25 de Mayo de 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.

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by