# 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.

10 views (last 30 days)
Ritvik Khanna on 20 Oct 2019
Edited: Andrei Bobrov 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

#### 1 Comment

darova on 21 Oct 2019
Trying to assign a matrix to (1,1) element?
T = [-4 1 0;1 -4 1;0 1 -4]
%% ...
A(i,j)=T

Stephan on 21 Oct 2019
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?