Output argument "y" (and maybe others) not assigned during call
2 ビュー (過去 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?
0 件のコメント
採用された回答
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.
1 件のコメント
Star Strider
2019 年 10 月 27 日
Assign ‘y’ first:
function y = ycal(x,x0,a)
y = NaN;
gamma=0.021;
... REST OF THE CODE ...
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!