How can I abort a extensive loop after a given amount of time in MATLAB 7.6 (R2008a)?

10 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This can be done by including a conditional IF statement in the loop that needs to be aborted after a certain time of computation has been exeeded. The example below uses the CLOCK and ETIME functions to compute the time and abort the loop with BREAK and END statements.
% Example - terminate loop after 60 seconds
t1=clock;
for i = 1:n
if (etime(clock,t1)>60), break, end
%do somthing
end
You could also work with RETURN or ERROR functions instead of the BREAK statement.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2008a

Community Treasure Hunt

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

Start Hunting!