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.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
darova
le 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
Réponses (2)
Stephan
le 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?
0 commentaires
Andrei Bobrov
le 21 Oct 2019
Modifié(e) : Andrei Bobrov
le 21 Oct 2019
A = kron(diag([1 1],1),I) + kron(diag([1 1],-1),I) + kron(eye(3),T);
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!