Unable to perform assignment because the left and right sides have a different number of elements
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Image Analyst
am 2 Nov. 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 Kommentare
Image Analyst
am 4 Nov. 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.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!