Constructing a try-catch loop

조회 수: 8 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by