Unable to perform assignment because the left and right sides have a different number of elements
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have the follwing matlab code. After excecuting it, error is displayed as "Unable to perform assignment because the left and right sides have a different number of elements." Kindly help me out.
k12=200;
k34=500;
K=zeros(4,4);
a=2:0.02:9;
b=1:length(a);
kc(b)=2:0.02:9;
for b=1:length(a)
kc(b)=2:0.02:9;
K(b)=[k12 -k12 0 0;-k12 kc(b)+k12 -kc(b) 0;0 -kc(b) k34+kc(b) -k34;0 0 -k34 k34];
end
0 comentarios
Respuestas (1)
Image Analyst
el 2 de Nov. de 2021
kc(b) is a single element because b is a single number between 1 and length(a).
2:0.02:9 is a 351 long row vector, NOT a single number.
You cannot stuff 351 numbers into an element meant to take only one number.
K(b) is a single element because b is a single number between 1 and length(a).
[k12 -k12 0 0;-k12 kc(b)+k12 -kc(b) 0;0 -kc(b) k34+kc(b) -k34;0 0 -k34 k34]; is a 4-by-4 matrix, NOT a single number.
You cannot stuff a 4x4 matrix into an element meant to take only one number.
6 comentarios
Image Analyst
el 4 de Nov. de 2021
Same problem and same question. You're trying to stick a 4x4 matrix into a location that can hold only one value. I don't know why you are trying to do that other than you saying you think you need to. But it's not allowed.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!