フィルターのクリア

Switch case error before to run simulation?

1 回表示 (過去 30 日間)
Tony Castillo
Tony Castillo 2016 年 6 月 1 日
コメント済み: Tony Castillo 2022 年 5 月 31 日
Hello can some one tell me why i get this mistake when i try to run the simulation?
Output argument 'battery' is not assigned on some execution paths.
Function 'MATLAB Function1' (#131.10.17), line 1, column 11:
"battery"
Launch diagnostic report.
function [battery, load, Emerg] = BattController1(SOC, Vconv)
%#codegen
persistent casevar
if isempty (casevar)
casevar=0;
end
switch (casevar)
% case 0
% if SOC==0 casevar=0;
% battery=0;
% load=0;
% Emerg=0;
% end
case 1
if SOC>=95 casevar=1;
load=1;
battery=0;
Emerg=0;
end
%suppliying load from batteries and disconnect it from PV panels charge in order to avoid overcharges
case 2
if (30<SOC) && (SOC<95) casevar=2;
load=1;
battery =1;
Emerg=0;
end
%suppliying load from batteries and batteries charging
case 3
if (SOC<30) && (Vconv>19) casevar=3;
load=0;
battery=1;
Emerg=1;
else
load=0;
battery=0;
Emerg=0;
end
%battery charging of PV panels and load disconected from batteries
otherwise
load=0;
battery=0;
Emerg=0;
end
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 31 日
case 1
if SOC>=95
if you got case 1 but SOC<95 then MATLAB will not look inside case 2 and the others to find matches, and will not activate the otherwise.
You should set the output values to the otherwise choices first, and then after that have your case that will fill in better values sometimes... and if not then the outputs will still be set to 0 or whatever you initialize
Tony Castillo
Tony Castillo 2022 年 5 月 31 日
@SALAH alatai It has been a while since I faced this issue, I can not find the file unfortunately.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 6 月 1 日
Suppose case 1 but SOC < 95, then what will battery be assigned?
  2 件のコメント
Tony Castillo
Tony Castillo 2016 年 6 月 1 日
I suppose you mean this: if SOC>=95 casevar=1; I still don't know what is the error.
Stephen23
Stephen23 2016 年 6 月 2 日
編集済み: Stephen23 2016 年 6 月 2 日
@Tony Castillo: read Walter's answer again: consider case 1 and SOC<95, then you do not define the outputs. But you call the function with some outputs, and yet they are not defined... thus the error.
The solution is to define the outputs for every possible permutation of states, or to define some default values once at the beginning of the function.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePropulsion and Power Systems についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by