## Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 3-by-3.

### Ritvik Khanna (view profile)

on 20 Oct 2019
Latest activity Edited by Andrei Bobrov

### Andrei Bobrov (view profile)

on 21 Oct 2019
My goal is to have a 9x9 matrix which looks like
T I 0 0 0 0 0 0 0
I T I 0 0 0 0 0 0
0 I T I 0 0 0 0 0
0 0 I T I 0 0 0 0
0 0 0 I T I 0 0 0
0 0 0 0 I T I 0 0
0 0 0 0 0 I T I 0
0 0 0 0 0 0 I T I
0 0 0 0 0 0 0 I T
0 0 0 0 0 0 0 0 T
Its a 2D matrix and not a multideminsional matrix however, the diagonal elements are another matrix. Below is my code
Can someone tell me what is wrong? Logically?
T = [-4 1 0;1 -4 1;0 1 -4]
I = [1 0 0;0 1 0;0 0 1]
A = zeros(9,9)
for i=1:9
for j=1:9
if i==j
A(i,j)=T
elseif j==(i+1)
A(i,j)=I
elseif j==(i-1)
A(i,j)=I
end
end
end

darova

### darova (view profile)

2019 年 10 月 21 日
Trying to assign a matrix to (1,1) element?
T = [-4 1 0;1 -4 1;0 1 -4]
%% ...
A(i,j)=T

### Stephan (view profile)

2019 年 10 月 21 日

You could check:
I used this function to build the matrix you expect - as far as i understood you correctly:
T = [-4 1 0;1 -4 1;0 1 -4];
I = [1 0 0;0 1 0;0 0 1];
A = zeros(9,9);
for k = 1:size(T,1):size(A,1)
A = linalg_substitute(A,T,k,k);
end
for k = 1:size(I,1):size(A,1)
A = linalg_substitute(A,I,k,k+size(T,2));
end
for k = size(I,1):size(I,1):size(A,1)
A = linalg_substitute(A,I,k+1,k-size(T,2)+1);
end
which produces:
A =
-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
Is this the desired result?

2019 年 10 月 21 日

### Andrei Bobrov (view profile)

2019 年 10 月 21 日

A = kron(diag([1 1],1),I) + kron(diag([1 1],-1),I) + kron(eye(3),T);