Output argument "y" (and maybe others) not assigned during call

1 次查看(过去 30 天)
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?

采纳的回答

Daniel M
Daniel M 2019-10-27
编辑:Daniel M 2019-10-27
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by