Stop the execution with a certain number of second

17 views (last 30 days)
J.J
J.J on 22 Mar 2019
Answered: J.J on 22 Mar 2019
I want to stop the execution with a certain number of seconds. In toher words, the script is running, but when the length is greater than 100 seconds, I want to stop the execution.
How I must do it?

Answers (2)

KSSV
KSSV on 22 Mar 2019
t1 = tic ;
while t1
t2 = toc(t1) ;
if t2 > 10
fprintf('loop breaked because 10 seconds passed\n')
break
end
end
  2 Comments
KSSV
KSSV on 22 Mar 2019
J.J commented: But I want to leave the script, not to stop during 10 seconds. So, I want that the script runs but when the legnth is x seconds, I want leave it.
KSSV
KSSV on 22 Mar 2019
break does the same right? It comes out of loop/ code.

Sign in to comment.


J.J
J.J on 22 Mar 2019
yes, but I tried to do it, and only it stops during the length established,later it continues running the code.
And i don't know why is it.
Do you know why it will happen?

Community Treasure Hunt

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

Start Hunting!