If statement should continue for some values even if "else" is true

1 visualización (últimos 30 días)
Harald Hermansson
Harald Hermansson el 26 de Nov. de 2022
Editada: Torsten el 26 de Nov. de 2022
I'm working with a Simulink model for a series hybrid vehicle. The statement I want to make is "if the battery percentage (SoC) drops below 35%, then turn on the engine and run it until it reaches 50%. But I don't know the way to make it continue to 50% because it's making the "else" statement true.
This is what I came up with so far, but this is of course not enough, should I implenent something like a "continue" statement?
function [w,T] = EnginePower(B_SoC)
if B_SoC < 0.4
T=12;
w=2500;
else
T=0;
w=0;
end

Respuestas (1)

Torsten
Torsten el 26 de Nov. de 2022
Editada: Torsten el 26 de Nov. de 2022
You must have a flag which indicates whether the engine is on or off.
function [w,T] = EnginePower(B_SoC)
persistent on
if isempty(on)
on = 0;
end
T = 0;
w = 0;
if on == 0
if B_SoC < 0.35
T = 12;
w = 2500;
on = 1;
end
end
if on == 1
if B_SoC <= 0.5
T = 12;
w = 2500;
else
on = 0
end
end
end

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by