MATLAB code to stop the program running when it meets conditions

3 ビュー (過去 30 日間)
Oliver Horrobin
Oliver Horrobin 2021 年 3 月 24 日
コメント済み: Oliver Horrobin 2021 年 3 月 24 日
Hi there,
I was wondering if it is possible to completely stop the run using code.
It would look something like this
cost = ooesCircDia
want = 30;
Test = round(cost,1);
if Test == want
% Where I need to stop the code <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elseif Test > want
cost = cost;
elseif Test < want
cost = - cost;
if cost < -want
cost = -cost;
end
end
So if Test = want the entire run stops.
Many thanks,
Ollie

採用された回答

DGM
DGM 2021 年 3 月 24 日
If you want everything to stop, use
return;
if you're in a loop and you just want to break out of the loop,
break;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by