Constructing a try-catch loop

6 ビュー (過去 30 日間)
sushma sharma
sushma sharma 2017 年 5 月 21 日
編集済み: Walter Roberson 2017 年 5 月 21 日
Hi,
I am trying to write a try-catch loop that will only fail on more than five attempts. how can i go about that?
So far, I have: try
%command to execute
catch
command to execute if error
end
how can i make this a loop that will only fail after five attempt at maximum?
any help would be appreciated,
sushma

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 21 日
編集済み: Walter Roberson 2017 年 5 月 21 日
fail_count = 0;
for fail_count = 1 : 5
try
THIS
break; %stop on first success
catch
if fail_count == 5
THAT
end
end
end

その他の回答 (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