Unable to perform assignment because the left and right sides have a different number of elements
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Image Analyst
2021 年 11 月 2 日
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 件のコメント
Image Analyst
2021 年 11 月 4 日
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.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!