I run the matlab script several times a day, and many times it takes too much time to execute. I want to make a timer that keeps track of how long the script is running and stops the script when it takes more time than the specified number of seconds
I tested this principle with a simple script:
waittime = 5; t = timer('TimerFcn','error(''Process ended because it took too long'')',waittime); start(t) pause(10);
What I would expect is that this function waits 5 seconds and then executes the stop function, which is the error('Process ended because it took too long') command.
When this is done, the stop command will be executed, however it does not stop the execution of the main script.
In my command window I see
Error while evaluating TimerFcn for timer 'timer-20' Process ended because it took too long
Then the script does not stop and continues to run for 10 seconds
I do not want this error to be executed on the TimerFcn function, I want this error to be executed on the running script in such a way that it stops working.
Is there any way to control the script / function that the error is running on?
source share