Paris
Paris

Reputation: 33

Matrix with the matrix elements

I want to create a matrix in large dimensions that the components themselves are a matrix.
Like the following example

enter image description here

each of the W, V, U is 18*18 matrix and the other components are zero. What is the easiest way to create such a matrix in MATLAB?

Upvotes: 3

Views: 57

Answers (1)

rahnema1
rahnema1

Reputation: 15837

Assuming that you want a matrix that contains n x n blocks so its dimensions will be (18 * n) x (18 * n):

n=10;
z=ones(n,1);
result = kron(spdiags(z,-1,n,n),V)+kron(spdiags(z,0,n,n),U)+kron(spdiags(z,1,n,n),W);

Upvotes: 4

Related Questions