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

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

Torsten
Torsten il 26 Nov 2022
Modificato: Torsten il 26 Nov 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

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by