MATLAB Answers

Unable to perform assignment because the left and right sides have a different number of elements.

1 ビュー (過去 30 日間)
Taha Oguz Özen
Taha Oguz Özen 2021 年 1 月 12 日
コメント済み: Jon 2021 年 1 月 13 日
problem solved. Thanks
  1 件のコメント
Jon 2021 年 1 月 13 日
I'm glad you solved your problem, but it looks like you deleted the text of your original post. It would be good to leave it up in case other people have a similar problem. Also, it leaves the answer I posted hanging without any context. If you still have a copy of it it would be good to put it back. If my answer below solved your problem please accept it.


回答 (1 件)

Jon 2021 年 1 月 12 日
編集済み: Jon 2021 年 1 月 12 日
I'm sorry I don't have time to fully understand your code, from a quick look I think your problem may be in your function at line 98
y2_2nd = @(t,q,dqdt) (Q_q-C_q.*dqdt.^2)./J_q;
along with the later line 102
k_12 = y2_2nd(t(i),q(i),dqdt(i));
Your function contains the terms Q_q and C_q both of which are vectors. This means that y2_2nd returns a vector and as result k_12 is also a vector. I'm thinking that you want k_12 to be a scalar constant.
Similar problems then occur in the later terms lines 103-108 so that finally at line 110 you are trying to assign a scalar, q(i+1) to a vector, since, k_21, k_31, and k_41 are all vectors so the right hand side of line 110 evaluates to a vector.
If you don't know how to use it already I would suggest learning how to use the MATLAB debugger, which is helpful for stepping through the code and examining variables as the calculation progresses


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by