Unable to perform assignment because the left and right sides have a different number of elements.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I am fairly new to programming and MATLAB so this may be an easy solution. Basically I am trying to solve for a variable and call it "x0(3)". When I run it however, I get an error saying "Unable to perform assignment because the left and right sides have a different number of elements."
This is my code,
syms sy F d g2
lsf=(g2==sy*((pi*d^2)/4)-F);
mem=[61000,60000,1.5];
std=[5200,15000,0.021];
n=3;
for i=1:2
x0(i)=mem(i)
end
a=solve (lsf,d);
x0(3)=vpa(subs(a,[sy F d g2],[x0(1) x0(2) d 0]))
and my output,
When I change x0(3) to a letter, like B, then I get the value I am looking for. Is there a way I can make the variable set to x0(3)?
Thank you!
2 commentaires
Geoff Hayes
le 14 Juin 2019
Jonathan - when you have something like
x0(3) = ...;
you are treating x0 as an array where you are setting the third element to a value. Do you mean for x0 to be an array? What are the dimensions of the output from vpa? I suspect that it isn't a scalar and that is why you are observing the error (and why it will work when you don't try to assign the output to an array).
Réponses (1)
madhan ravi
le 14 Juin 2019
No loops needed:
syms sy F d g2
lsf=(g2==sy*((pi*d^2)/4)-F);
mem=[61000,60000,1.5];
std=[5200,15000,0.021];
n=3;
x0=mem(1:2);
a=solve(lsf,d);
b=vpa(subs(a,[sy F d g2],[x0(1) x0(2) d 0]));
Wanted=[repmat(x0,size(b)),b]
0 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!