How to set stopping condition on time in nested for loop?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
tStart = cputime;
c=0;
while 1
if cputime-tStart>20
break
end
c=c+1;
end
c
3 Kommentare
Walter Roberson
am 21 Okt. 2022
A question would be whether to stop based on cpu time or based on elapsed time.
Noor Fatima
am 21 Okt. 2022
Noor Fatima
am 21 Okt. 2022
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!