Error: Unable to perform assignment because the left and right sides have a different number of elements.
5 次查看(过去 30 天)
显示 更早的评论

Why am I getting this error message? I have no idea what I did incorrectly. Thanks
3 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!