Error: Unable to perform assignment because the left and right sides have a different number of elements.
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

Why am I getting this error message? I have no idea what I did incorrectly. Thanks
3 commentaires
Walter Roberson
le 3 Avr 2025
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))
Réponses (1)
Harshavardhan
le 3 Avr 2025
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 commentaires
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!