Output argument m_dot_B is not assigned on some execution paths
3 次查看(过去 30 天)
显示 更早的评论
Hello guys, I have a question about Matlab. When i run the simulation, Matlab give instruction " Output argument is not assigned on some execution path. Below my coding that i using in matlab and im using "matlab function" block. Hope you can help me Thank you
function m_dot_B = fcn(Av, PB) %#codegen
k = 1.4; Cf=0.7; T=294.5; C1=0.0404; C2=0.1562; Pcr=0.528; Ps=5*exp(5);
if PB/Ps <= Pcr
m_dot_B = Cf*Av*C1*(Ps/T^(1/2));
elseif PB/Ps > Pcr
m_dot_B = Cf*Av*C2*(Ps/T^(1/2)*((PB/Ps)^(1/k))*(1-(PB/Ps)^((k-1)/k))^(1/2));
end
0 个评论
采纳的回答
Image Analyst
2013-11-17
It's possible that neither of your if tests will be true, and if that happens, then fcn would return without having set anything for m_dot_B. A more robust way to write the code would be like this:
function m_dot_B = fcn(Av, PB) %#codegen
% Initialize output in case something goes wrong.
m_dot_B = 0;
try
k = 1.4;
Cf=0.7;
T=294.5;
C1=0.0404;
C2=0.1562;
Pcr=0.528;
Ps=5*exp(5);
if PB/Ps <= Pcr
m_dot_B = Cf*Av*C1*(Ps/T^(1/2));
else
m_dot_B = Cf*Av*C2*(Ps/T^(1/2)*((PB/Ps)^(1/k))*(1-(PB/Ps)^((k-1)/k))^(1/2));
end
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage);
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Software Development Tools 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!