Variable ... is undefined on some execution paths
조회 수: 86 (최근 30일)
이전 댓글 표시
Smaghuli
2015년 4월 17일
댓글: Elisa Micaela Rodriguez Steinbrecher
2022년 12월 1일
hello guys!
I hope somebody can advise me with respect the next code, when I run it into embedded editor from simulink embedded block, I have the error that Variable 'mu1' is undefined on some execution paths.
function [u_F,mu12,mu32] = fcn(s,delta)
%#codegen
a = 0.5;
mu12 = 0;
mu32 = 0;
y = 0;
if s <= -a
mu1 = 1;
mu2 = 0;
mu3 = 0;
elseif -a < s && s <= 0
mu1 = -1/a*s;
mu2 = 1/a*(s+a);
mu3 = 0;
elseif s > 0 && a >= s
mu1 = 0;
mu2 = -1/a*(s-a);
mu3 = 1/a*s;
elseif s > a
mu1 = 0;
mu2 = 0;
mu3 = 1;
end
mu12 = mu1;
mu32 = mu3;
y = (mu1*(-delta)+mu2*0+mu3*delta)/(mu1+mu2+mu3);
u_F = y;
댓글 수: 0
채택된 답변
Ryan Livingston
2015년 4월 27일
편집: Ryan Livingston
2015년 4월 27일
As the error says, there is a possible execution path on which mu1 is not defined. In particular, if all of the conditions in your if and elseif statements are false, then mu1,mu2,mu3 will not be defined.
To resolve this define them to default values either before the if:
mu1 = 0; mu2 = 0; mu3 = 0;
if s<= -1 ...
or add an else branch:
elseif s > a
mu1 = 0;
mu2 = 0;
mu3 = 1;
else
mu1 = 0;
mu2 = 0;
mu3 = 0;
end
댓글 수: 3
Ambe Harrison
2022년 7월 19일
Thank you Ryan Livingston your comment was very useful. It just solved a similar problem i encoutered.
Kind regards.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!