Output argument "y" (and maybe others) not assigned during call
1 view (last 30 days)
Show older comments
sanjay srinivaas
on 27 Oct 2019
Commented: Star Strider
on 27 Oct 2019
function y = ycal(x,x0,a)
gamma=0.021;
L=0.3*10^-2;
theta=0;
d=0.3*10^-3;
E=72*10^9;
I=3.976*10^-16;
A=2*gamma*cos(theta)*(2*a+d);
L1=x0;
offset=0.3*10^-3;
if(x<=L1)
y=(A/(E*I))*(x^3/6-(L1+a)*x^2/2)+offset;
elseif(L1<x&&x<=(L1+2*a))
T=(1+(L1)/2*a)/6;
U=(L1+a+(L1^2)/4*a)/2;
V=1/48*a;
W=L1^3/12*a;
X=L1^4/48*a;
y=(A/(E*I))*((x^3*T)-(x^2*U)-(x^4*V)+(x*W)-(1*X))+offset;
elseif((L1+2*a)<x&&x<=L)
Y=(L1^2+a*L1+(2/3)*a^2);
Z=((2/3)*L1^3+(2/3)*a^2*L1+(3/2)*a*L1^2+a^3/3);
y=(A/(E*I))*(-x*Y+Z)+offset
end
end
I'm getting this error"
Error in ycal (line 2)
gamma=0.021;
Output argument "y" (and maybe others) not assigned during call to "C:\Users\Admin\Documents\MATLAB\Proj\ycal.m>ycal"."
Could someone find the mistake please?
0 Comments
Accepted Answer
Daniel M
on 27 Oct 2019
Edited: Daniel M
on 27 Oct 2019
What is the function supposed to return for y = ycal(1,0,0)? It doesn't pass any of the conditionals in the if statement. And since there is no default value for y, it cannot assign an output for y. Therefore, you need to handle the default value for y, perhaps by putting:
else
y = NaN;
end
Or something to that effect.
1 Comment
Star Strider
on 27 Oct 2019
Assign ‘y’ first:
function y = ycal(x,x0,a)
y = NaN;
gamma=0.021;
... REST OF THE CODE ...
end
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!