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

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

回答 (2 件)

Catalytic
Catalytic 2024 年 4 月 19 日

1 投票

if abs( out.soc_fin(end)-soc_target ) <= 1.5
VBBV
VBBV 2024 年 4 月 19 日
編集済み: VBBV 2024 年 4 月 19 日

0 投票

Another way is to use isequal function
if isequal((out.soc_fin(end)-soc_target),1.5)
break
end

1 件のコメント

DGM
DGM 2024 年 4 月 19 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2024 年 4 月 19 日

コメント済み:

DGM
2024 年 4 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by