Azzera filtri
Azzera filtri

Variable "Flag" is not fully defined in some execution paths. Why?

2 visualizzazioni (ultimi 30 giorni)
function [Gs1, Gs2, Gs3] = mpp(Ppv, Po, T, Ipv, Vbat)
persistent Flag0
if isempty(Flag0)
Flag0 = 1; Flag = 1;
end
Vbnom = 45; Vbmax = 50;
if(mod(T,0.02)== 0)
while (Flag0 == 1)
while (Vbat <= Vbnom)
Gs1 = 1;
Gs2 = 1;
Gs3 = 0;
Flag = 2;
Flag0 = Flag;
return
end
while (Vbat > Vbnom)
Gs1 = 1;
Gs2 = 0;
Gs3 = 1;
Flag = 3;
Flag0 = Flag;
return
end
end
while (Flag0 == 2)
while (Ipv <= 0)
Gs1 = 0;
Gs2 = 0;
Gs3 = 1;
Flag = 1; Flag0 = Flag;
return
end
while (Ipv > 0)
while (Ppv >= Po)
while (Vbat >= Vbmax)
Gs1 = 1;
Gs2 = 0;
Gs3 = 1;
Flag = 3;
Flag0 = Flag;
return
end
while (Vbat < Vbmax)
Gs1 = 1;
Gs2 = 1;
Gs3 = 0;
Flag = 1; Flag0 = Flag;
return
end
end
while (Ppv < Po)
Gs1 = 1;
Gs2 = 0;
Gs3 = 1;
Flag = 3; Flag0 = Flag;
return
end
end
end
while (Flag0 == 3)
while (Ipv <= 0)
Gs1 = 0;
Gs2 = 0;
Gs3 = 1;
Flag = 1; Flag0 = Flag;
return
end
while (Ipv > 0)
while (Ppv > Po)
Gs1 = 1;
Gs2 = 1;
Gs3 = 0;
Flag = 2; Flag0 = Flag;
return
end
while (Ppv <= Po)
Gs1 = 1;
Gs2 = 0;
Gs3 = 1;
Flag = 3; Flag0 = Flag;
return
end
end
end
while (Flag0 > 3) || (Flag0 < 0)
Gs1 = 1;
Gs2 = 0;
Gs3 = 1;
Flag = 1; Flag0 = Flag;
end
else
Flag = 1;
Gs1 = 1;
Gs2 = 1;
Gs3 = 0;
end
Flag0 = Flag;

Risposte (1)

Star Strider
Star Strider il 29 Ott 2022
Because there are conditional statements in the code, and not all of them set the ‘Flag’ variable.
One way to avoid that is to set it to something at the beginning of the code, for example —
function [Gs1, Gs2, Gs3] = mpp(Ppv, Po, T, Ipv, Vbat)
Flag = NaN;
... REST OF THE CODE ...
end
or whatever default value for it makes sense in context.
.

Categorie

Scopri di più su Simulink Environment Customization in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by