how can i stop this while loop? it doesn;t finish

2 vues (au cours des 30 derniers jours)
Youngjin
Youngjin le 19 Avr 2024
Commenté : DGM le 19 Avr 2024
while 1
sim(mdl);
if out.soc_fin(end)-soc_target <= 1.5
break
end
on_line = on_line + 1000;
end
the mdl is simulink that calculate soc,
although the SOC reach the if target, it doesn't finish and SOC is going down,
please help me

Réponses (2)

Catalytic
Catalytic le 19 Avr 2024
if abs( out.soc_fin(end)-soc_target ) <= 1.5

VBBV
VBBV le 19 Avr 2024
Modifié(e) : VBBV le 19 Avr 2024
Another way is to use isequal function
if isequal((out.soc_fin(end)-soc_target),1.5)
break
end
  1 commentaire
DGM
DGM le 19 Avr 2024
That's only going to work if the error is exactly 1.5. If it undershoots the maximum allowable error, it'll just keep going.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Embedded Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by