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

4 ビュー (過去 30 日間)
Why am I getting this error message? I have no idea what I did incorrectly. Thanks
  3 件のコメント
Frank Kostecki
Frank Kostecki 2021 年 4 月 8 日
I have them defined beforehand so I don't understand
Walter Roberson
Walter Roberson 2025 年 4 月 3 日
One of drag or area or mass are non-scalar. With regards to mass: since there is the / operation there and the / operation succeeded, we can deduce that mass must be either scalar or a column vector. Because the drag * area succeeded, we can deduce that either one of them is scalar or else the two just happen to have matching "inner dimensions" (size(drag,2) == size(area,1))

サインインしてコメントする。

回答 (1 件)

Harshavardhan
Harshavardhan 2025 年 4 月 3 日
The error message indicates that there is a mismatch in the number of elements on the left and right sides of an assignment. This typically happens when you try to assign a vector or matrix to a scalar or vice versa.
Check and ensure that all the variables used are of the right dimension by using the function “size”.
size_mass = size(mass)
size_pos_x = size(pos_x)
size_pos_y = size(pos_y)
size_vel_x = size(vel_x)
size_vel_y = size(vel_y)
size_acc_x = size(acc_x)
size_acc_y = size(acc_y)
size_vel = size(vel)
size_rho = size(rho)
size_drag = size(drag)
size_area = size(area)
size_grav = size(grav)
Make sure that the dimensions of both sides of the assignment are compatible and make changes where needed.
For more information on “size” you can type the following command into a MATLAB command window:
doc size
Hope this helps.

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by