How to solve this issue Variable 'X' is not fully defined on some execution paths.

Dear All,
I have a code into a MATLABFUNCTION block of Simulink that jump out this error message "
Variable 'CONDICIONTRAMO' is not fully defined on some execution paths. Function 'Battery_Control/Function_Cruz_v2' (#25.1881.1895), line 57, column 12: "CONDICIONTRAMO" Launch diagnostic report."
Anyone of you can help me out to find the way to solve this ? Please.
function [SOC_CC, Bat_charge] = BUsage(top, SOC, SOC_Seg, SOCint, W_demand, Power_PV)
if SOC>=SOC_Seg
SOC_CC=0;
Bat_charge=0;
return
else
if SOC>=SOCint
SOC_CC=1;
Bat_charge=0;
end
if SOC<=SOCint
if (top>=8)||(top<=9) && Power_PV>W_demand
CONDICIONTRAMO = 1;
disp('Llano 1 de 8 a 9')
elseif (top>=8)||(top<=9) && Power_PV<W_demand
CONDICIONTRAMO = 2;
disp('"-" Llano 1 de 8 a 9')
elseif (top>=10)||(top<=13) && Power_PV>W_demand
CONDICIONTRAMO = 3;
disp('Punta 1 de 10 a 13')
elseif (top>=10)||(top<=13) && Power_PV<W_demand
CONDICIONTRAMO = 4;
disp('"-"Punta 1 de 10 a 13')
elseif (top>=14)||(top<=17) && Power_PV>W_demand
CONDICIONTRAMO = 5;
disp('Llano 2 de 14 a 17')
elseif (top>=14)||(top<=17) && Power_PV<W_demand
CONDICIONTRAMO = 6;
disp('"-"Llano 2 de 14 a 17')
elseif (top>=18)||(top<=21)&& Power_PV>W_demand
CONDICIONTRAMO = 7;
disp('Punta 2 de 18 a 21')
elseif (top>=18)||(top<=21)&& Power_PV<W_demand
CONDICIONTRAMO = 8;
disp('"-"Punta 2 de 18 a 21')
elseif (top>=22)||(top<=23)&& Power_PV>W_demand
CONDICIONTRAMO = 9;
disp('Llano 3 de 22 a 23:59')
elseif (top>=22)||(top<=23)&& Power_PV<W_demand
CONDICIONTRAMO = 10;
disp('"-"Llano 3 de 22 a 23:59')
elseif (top>=24)||(top<=8) && Power_PV<W_demand
CONDICIONTRAMO =11;
disp('Valle de 24 a 8')
end
switch CONDICIONTRAMO
case 1
SOC_CC=1;
Bat_charge=0;
case 2
SOC_CC=0;
Bat_charge=0;
case 3
SOC_CC=1;
Bat_charge=0;
case 4
SOC_CC=0;
Bat_charge=0;
case 5
SOC_CC=1;
Bat_charge=0;
case 6
SOC_CC=0;
Bat_charge=0;
case 7
SOC_CC=1;
Bat_charge=0;
case 8
SOC_CC=0;
Bat_charge=0;
case 9
SOC_CC=1;
Bat_charge=0;
case 10
SOC_CC=0;
Bat_charge=0;
case 11
SOC_CC=1;
Bat_charge=1;
otherwise
disp('No')
end
end
end
end

 Accepted Answer

Insert a definition of CONDICIONTRAMO = -1 (or NaN, or 12) either on top of the code, before the IF branchs, or in a finaly else branch:
...
elseif (top>=24)||(top<=8) && Power_PV<W_demand
CONDICIONTRAMO =11;
disp('Valle de 24 a 8')
else
CONDICIONTRAMO = 12;
end
But then Bat_charge is not defined in all branchs. Add a default value for this variable also.
By the way, the Switch/Case-Block is hard to read. Maybe this is tougher:
% 1 2 3 4 5 6 7 8 9 10 11 12
SOC_CC_V = [1 0 1 0 1 0 1 0 1 0 1 NaN];
Bat_charge_V = [0 0 0 0 0 0 0 0 0 0 1 NaN];
SOC_CC = SOC_CC_V(CONDICIONTRAMO);
Bat_charge = Bat_charge_V(CONDICIONTRAMO);

7 Comments

Mr where in the code should I set those ?
% 1 2 3 4 5 6 7 8 9 10 11 12
SOC_CC_V = [1 0 1 0 1 0 1 0 1 0 1 NaN];
Bat_charge_V = [0 0 0 0 0 0 0 0 0 0 1 NaN];
SOC_CC = SOC_CC_V(CONDICIONTRAMO);
Bat_charge = Bat_charge_V(CONDICIONTRAMO);
Ir replaces this block of code:
switch CONDICIONTRAMO
case 1
SOC_CC=1;
Bat_charge=0;
case 2
SOC_CC=0;
Bat_charge=0;
case 3
SOC_CC=1;
Bat_charge=0;
case 4
SOC_CC=0;
Bat_charge=0;
case 5
SOC_CC=1;
Bat_charge=0;
case 6
SOC_CC=0;
Bat_charge=0;
case 7
SOC_CC=1;
Bat_charge=0;
case 8
SOC_CC=0;
Bat_charge=0;
case 9
SOC_CC=1;
Bat_charge=0;
case 10
SOC_CC=0;
Bat_charge=0;
case 11
SOC_CC=1;
Bat_charge=1;
otherwise
disp('No')
end
Sir Jan, it runs now but it is stuck in the first CONDICIONTRAMO even though I am inserting the rest of the condition (using a clock) I find it difficult to work in Simulink using time for verifying the conditions, do you have any insights as to why this gets hooked in one value (in this case in 5, despite the clock runs through the 24 hours)?.
Sorry, I do not understand, what you are asking for. Which "clock"?
Thank Jan, I think I have addressed it properly. I comment it to yo just to inform you about my previous problem, I have noticed that when I included a Simulink clock into my Simulink model, the battery steped down like a short circuit, this is a pretty unexpectable issue.
As far as I understand, this is another problem. If so, please open a new thread to get support.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2021a

Asked:

on 30 Jun 2021

Commented:

on 2 Jul 2021

Community Treasure Hunt

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

Start Hunting!