How to set stopping condition on time in nested for loop?
Show older comments
tic
Time = 0;
flag = 0;
for kk = 1: n
some operations
for ii = 1:m
if Time >= Time_limit
flag = 1;
break
end
some operations
end
Time = toc;
if(flag==1)
break
end
end
But the above code does not stop when a time limit reached.
Accepted Answer
More Answers (1)
tStart = cputime;
c=0;
while 1
if cputime-tStart>20
break
end
c=c+1;
end
c
3 Comments
Walter Roberson
on 21 Oct 2022
A question would be whether to stop based on cpu time or based on elapsed time.
Noor Fatima
on 21 Oct 2022
Noor Fatima
on 21 Oct 2022
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!