Unable to perform assignment because the left and right sides have a different number of elements.
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Geoff Hayes
2019년 6월 14일
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).
답변 (1개)
madhan ravi
2019년 6월 14일
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
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!