Variable 'ep3' is undefined on some execution paths.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
azadeh jalali
am 21 Feb. 2021
Kommentiert: azadeh jalali
am 24 Feb. 2021
Hello dears,
I'm using the block named Embedded MATLAB (that link the simulink to matlab) and when I try to run the code above, return the message errors: "Variable 'ep3' is undefined on some execution paths", "Variable 'edotp3' is undefined on some execution paths". However, I define these parameters in the embedded matlab function. In below code I identified the line of error.
function y_3 = fcn3_2star_Edit_01(ys1,ys2)
de3=ys1
e3=ys2
x0nb_up=-0.9; x0z_up=-0.1; x0pb_up=0.9;
x0nb=-1; x0z=0; x0pb=1;
x0nb_bot=-1.1; x0z_bot=0.1; x0pb_bot=1.1;
%% x0z1=0; x0p=1; x0n=-1;
%%%% Mu&SigmaForMF %%%%
muP=1; muZ=0; muN=-1; sigma=0.0598957;
if e3<=x0pb && e3>0
ep3=1*max(0,exp(-(e3-x0pb)^2/0.16))
else
if e3 <=0
ep3=0;
else
if e3 >x0pb
ep3=1*max(0,1)
end
end
end
%%%%%
if e3<=x0z && e3>x0nb
ez3=1*max(0,exp(-(e3-x0z)^2/0.16));
else
if e3>=x0z && e3<x0pb
ez3=1*max(0,exp(-(e3-x0z)^2/0.16));
else
if e3<=x0nb
ez3=0 ;
else
if e3>=x0pb
ez3=0;
end
end
end
end
%%%%%
if e3<x0nb
en3=1*max(0,1);
else
if e3>=x0nb && e3<0
en3=1*max(0,exp(-(e3-x0nb)^2/0.16));
else
if e3>=0
en3=0;
end
end
end
%%%%%%%%%%%%%%%%%%%%
if de3<=x0p && de3>0
edotp3=1*max(0,exp(-(de3-x0p)^2/0.16));
else
if de3 <=0
edotp3=0;
else
if de3>x0p
edotp3=1*max(0,1);
end
end
end
%%%%%
if de3<=x0z && de3>x0nb
edotz3=1*max(0,exp(-(de3-x0z)^2/0.16));
else
if de3>=x0z && de3<x0pb
edotz3=1*max(0,exp(-(de3-x0z)^2/0.16));
else
if de3<=x0nb
edotz3=0 ;
else
if de3>=x0pb
edotz3=0;
end
end
end
end
%%%%%
if de3<x0n
edotn3=1*max(0,1);
else
if de3>=x0n && de3<0
edotn3=1*max(0,exp(-(de3-x0n)^2/0.16));
else
if de3>=0
edotn3=0;
end
end
end
%%%%%%%%%%%%%%
if 0< ep3 && ep3 <1 %%% The ERROR is in this line
p_ep3=(1/((2*sqrt(2*pi))*ep3*sigma))*sqrt(-0.16/(log(ep3)))*(exp(-(sqrt(-0.16*log(ep3))+e3-muP)^2/(2*sigma^2))+exp(-(-sqrt(-0.16*log(ep3))+e3-muP)^2/(2*sigma^2)));
PP_ep3=1-((erf((sqrt(-0.08*log(ep3))+(muP/(2^0.5))-(e3/(2^0.5)))/sigma)+erf((sqrt(2)*sqrt(-0.08*log(ep3))-muP+e3)/(sqrt(2)*sigma)))/(sqrt(2)))
else
p_ep3=0;
PP_ep3 =0;
end
%%%%%%%%%%%%%%
if 0< edotp3 && edotp3 <1 %%% The ERROR is in this line
p_edotp3=(1/((2*sqrt(2*pi))*edotp3*sigma))*sqrt(-0.16/(log(edotp3)))*(exp(-(sqrt(-0.16*log(edotp3))+de3-muP)^2/(2*sigma^2))+exp(-(-sqrt(-0.16*log(edotp3))+de3-muP)^2/(2*sigma^2)));
PP_edotp3=1-((erf((sqrt(-0.08*log(edotp3))+(muP/(2^0.5))-(de3/(2^0.5)))/sigma)+erf((sqrt(2)*sqrt(-0.08*log(edotp3))-muP+de3)/(sqrt(2)*sigma)))/(sqrt(2)))
else
p_edotp3=0;
PP_edotp3=0;
end
%%%%%%
........ the code is continuded
My code is too longe, so I only put the beginig of it up to where there is problem.
0 Kommentare
Akzeptierte Antwort
Jan
am 21 Feb. 2021
Bearbeitet: Jan
am 21 Feb. 2021
The message "undefined on some execution paths" means, that there is a possible combination of IF-branches, in which the variable is not defined anywhere. The solution is to create a default value before the IF branchs. This oul simplify your code massively in addition.
Replace:
if e3<=x0pb && e3>0
ep3=1*max(0,exp(-(e3-x0pb)^2/0.16))
else
if e3 <=0
ep3=0;
else
if e3 >x0pb
ep3=1*max(0,1)
end
end
end
by
ep3 = 0;
if e3 <= x0pb && e3 > 0
ep3 = 1 * max(0, exp(-(e3 - x0pb)^2 / 0.16)); % "1*" ?!?
elseif e3 > x0pb
ep3 = 1; % "1*max(0,1)" ?!?
end
The other parts can be simplified also in an equivalent way. E.g.:
if de3<=x0z && de3>x0nb
edotz3=1*max(0,exp(-(de3-x0z)^2/0.16));
else
if de3>=x0z && de3<x0pb
edotz3=1*max(0,exp(-(de3-x0z)^2/0.16));
else
if de3<=x0nb
edotz3=0 ;
else
if de3>=x0pb
edotz3=0;
end
end
end
end
can be simpified to:
edotz3 = 0;
if (de3 <= x0z && de3 > x0nb) || ...
de3 >= x0z && de3 < x0pb)
edotz3 = exp(-(de3 - x0z)^2 / 0.16);
end
Note: max(0, exp(x)) is the same as exp(x), because the result is >= 0 in every case.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Electrical Block Libraries finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!