フィルターのクリア

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

2 ビュー (過去 30 日間)
satabdi bhattacharya
satabdi bhattacharya 2022 年 10 月 29 日
回答済み: Star Strider 2022 年 10 月 29 日
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;

回答 (1 件)

Star Strider
Star Strider 2022 年 10 月 29 日
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.
.

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by