Output argument 'x' is not assigned on some execution paths.
161 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Serdar GÜNAY
el 30 de Oct. de 2020
Comentada: akhongbam
el 6 de Feb. de 2024
Hello, I wrote the following code in the Matlab function in simulink and the error "Outut argument 'x' is not assigned on some execution paths" occurred. I don't know why the code not working. I hope you can help me. Thank you
My simulink function block have this code:
function [x,y] = fcn(u)
% u = battery voltage
% x=1 battery charge switch
% y=1 battery discharge switch
if (u<=0.9) % battery charge
while (u<=1.2)
x=1;
y=0;
end
elseif (u>1.2) || (u>0.9) && (u<1.2) %battery discharge
while (u>=0.9)
x=0;
y=1;
end
else
x=0;
y=0;
end
end
0 comentarios
Respuesta aceptada
Ameer Hamza
el 30 de Oct. de 2020
Editada: Ameer Hamza
el 30 de Oct. de 2020
Ok. I suspect you are trying to run this code on Simulink in the MATLAB function block. Since you didn't provide this information, so it is difficult to see what the issue is. Simulink use C/C++ code-generation and then compile your model. Therefore, it is necessary to initialize your variables, even if they will get their values later in code execution. Therefore, at the beginning of your function, initialize x, and y
function [x,y] = fcn(u)
% u = battery voltage
% x=1 battery charge switch
% y=1 battery discharge switch
x = 0; % this initialization is necessary for Simulink. Even if this is not goint to be used
y = 0;
% rest of your code
Also, use 'if', instead of while as pointed out by KSSV.
7 comentarios
蒙召 张
el 18 de En. de 2022
Thank you. I have the same problem. Your answer was very useful and solved my problem
akhongbam
el 6 de Feb. de 2024
guys can u help in coding for active cell balancing
this is my code
function [s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14] = fcn(soc1,soc2,soc3,soc4,soc5,soc6,soc7,pwm1,pwm2)
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;
s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
high= max([soc1 soc2 soc3 soc4 soc5 soc6 soc7]);
low = min([soc1 soc2 soc3 soc4 soc5 soc6 soc7]);
if high==soc1&&low==soc2
s1=pwm1;s2=1;s5=pwm2;
s3=0;s4=0;s6=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc1&&low==soc3
s1=pwm1;s2=pwm1;s4= pwm2;s7=pwm2;
s3=0;s5=0;s6=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc1&&low==soc4
s1=pwm1;s2=pwm1;s6=pwm2;
s3=0;s4=0;s5=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc1&&low==soc5
s1=pwm1; s4=pwm1; s7= pwm2;s11=pwm2;
s2=0;s3=0;s5=0;s6=0;s8=0;s9=0;s10=0;s12=0;s13=0;s14=0;
elseif high==soc1&&low==soc6
s1=pwm1;s7=pwm1;s10=pwm2;s12=pwm2;
s2=0;s3=0;s4=0;s5=0;s6=0;s8=0;s9=0;s11=0;s13=0;s14=0;
% soc2 starts here
elseif high==soc2&&low==soc1
s3=1;s4=pwm1;
s1=0;s2=0;s5=0;s6=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc2&&low==soc3
s3=pwm1;s5=pwm1;
s1=0;s2=0;s6=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc2&&low==soc4
s3=pwm1;s4=pwm1;s6=pwm2;
s1=0;s2=0;s5=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
%soc3 starts here
elseif high==soc3&&low==soc1
s3=pwm2;s5=pwm1;s6=pwm1;
s1=0;s2=0;s4=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc3&&low==soc2
s2=pwm1;s6=pwm2;s5=1;
s1=0;s3=0;s4=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc3&&low==soc4
s5=pwm1;s6=1;
s1=0;s2=0;s3=0;s4=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc3&&low==soc5
s5=pwm1;s7=pwm1;s9=pwm2;
s1=0;s2=0;s3=0;s4=0;s6=0;s8=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc3&&low==soc6
s5=pwm1;s7=pwm1;s9=pwm2;s11=pwm2;
s1=0;s2=0;s3=0;s4=0;s6=0;s8=0;s10=0;s12=0;s13=0;s14=0;
elseif high==soc3&&low==soc7
s5=pwm1;s7=1;s9=pwm1;s11=pwm2;s13=pwm2;
s1=0;s2=0;s3=0;s4=0;s6=0;s8=0;s10=0;s12=0;s14=0;
%soc4 starts here
elseif high==soc4&&low==soc1
s3=pwm2;s7=pwm1;s8=pwm1;
s1=0;s2=0;s4=0;s5=0;s6=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc4&&low==soc2
s2=pwm2;s5=pwm2;s7=pwm1;s8=pwm1;
s1=0;s3=0;s4=0;s6=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc4&&low==soc3
s4=pwm2;s8=pwm1;s7=1;
s1=0;s2=0;s3=0;s5=0;s6=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc4&&low==soc5
s7=pwm1;s9=pwm1;s10=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s8=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc4&&low==soc6
s7=pwm1;s9=pwm1;s11=pwm2;s12=1;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s8=0;s10=0;s13=0;s14=0;
elseif high==soc4&&low==soc7
s7=pwm1;s9=1;s11=pwm1;s13=pwm2;s14=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s8=0;s10=0;s12=0;
%soc5 starts here
elseif high==soc5&&low==soc1
s10=pwm1;s9=pwm1;s2=pwm2;s4=pwm2;s6=1;
s1=0;s3=0;s5=0;s7=0;s8=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc5&&low==soc2
s10=pwm1;s7=pwm1;s4=pwm2;s3=pwm2;
s1=0;s2=0;s5=0;s6=0;s8=0;s9=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc5&&low==soc3
s10=pwm1;s9=pwm1;s6=pwm2;s5=pwm2;
s1=0;s2=0;s3=0;s4=0;s7=0;s8=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc5&&low==soc4
s10=pwm1;s8=pwm1;s7=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s9=0;s11=0;s12=0;s13=0;s14=0;
elseif high==soc5&&low==soc6
s9=pwm1;s11=pwm1;s12=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s10=0;s13=0;s14=0;
elseif high==soc5&&low==soc7
s9=pwm1;s11=pwm1;s12=pwm2;s14=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s10=0;s8=0;s13=0;
%soc6 starts here
elseif high==soc6&&low==soc1
s12=pwm1;s10=1;s8=pwm1;s2=pwm2;s4=pwm2;
s1=0;s3=0;s5=0;s6=0;s7=0;s9=0;s11=0;s13=0;s14=0;
elseif high==soc6&&low==soc2
s12=pwm1;s10=pwm1;s6=pwm2;s3=pwm2;s4=1;
s1=0;s2=0;s5=0;s7=0;s8=0;s9=0;s11=0;s13=0;s14=0;
elseif high==soc6&&low==soc3
s12=pwm1;s9=pwm1;s6=pwm2;s5=pwm2;
s1=0;s2=0;s3=0;s4=0;s7=0;s8=0;s10=0;s11=0;s13=0;s14=0;
elseif high==soc6&&low==soc4
s12=pwm1;s10=pwm1;s8=pwm2;s7=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s9=0;s11=0;s13=0;s14=0;
elseif high==soc6&&low==soc5
s12=pwm1;s10=pwm1;s9=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s11=0;s13=0;s14=0;
elseif high==soc6&&low==soc7
s11=pwm1;s13=pwm1;s14=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s9=0;s10=0;s12=0;
%soc7 starts here
elseif high==soc7&&low==soc1
s14=pwm1;s13=pwm1;s9=pwm2;s7=1;s2=pwm2;s5=1;
s1=0;s3=0;s4=0;s6=0;s8=0;s10=0;s11=0;s12=0;
elseif high==soc7&&low==soc2
s14=pwm1;s11=pwm1;s9=pwm2;s3=pwm2;s5=1;
s1=0;s2=0;s4=0;s6=0;s7=0;s8=0;s10=0;s12=0;s13=0;
elseif high==soc7&&low==soc3
s14=pwm1;s12=pwm1;s5=pwm2;s9=pwm2;s7=1;
s1=0;s2=0;s3=0;s4=0;s6=0;s8=0;s10=0;s11=0;s13=0;
elseif high==soc7&&low==soc4
s14=pwm1;s11=pwm1;s9=pwm2;s7=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s8=0;s10=0;s12=0;s13=0;
elseif high==soc7&&low==soc5
s14=pwm1;s12=pwm1;s10=pwm2;s9=pwm2;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s11=0;s13=0;
elseif high==soc7&&low==soc6
s14=pwm1;s11=pwm2;s13=pwm1;
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s9=0;s10=0;s12=0;
else
s1=0;s2=0;s3=0;s4=0;s5=0;s6=0;s7=0;s8=0;s9=0;s10=0;s11=0;s12=0;s13=0;s14=0;
end
end
the code is running but it didnt balance
Más respuestas (1)
KSSV
el 30 de Oct. de 2020
You should not use while. Repalce it with if.
function [x,y] = fcn(u)
% u = battery voltage
% x=1 battery charge switch
% y=1 battery discharge switch
if (u<=0.9) % battery charging
if (u<=1.2)
x=1;
y=0;
end
elseif (u>1.2) || (u>0.9) && (u<1.2) %battery discharge
if (u>=0.9)
x=0;
y=1;
end
else
x=0;
y=0;
end
end
8 comentarios
KSSV
el 30 de Oct. de 2020
Hey...it is not you are opposing me...I said it because..now you understood the gist..and you can do it...
Ver también
Categorías
Más información sobre Energy Storage en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!