MATLAB: Switch case error before to run simulation

assignederrorMATLABMATLAB and Simulink Student Suite

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

Best Answer

Suppose case 1 but SOC < 95, then what will battery be assigned?