How to stop a function if it exceeds a certain time?

9 Ansichten (letzte 30 Tage)
samudra s
samudra s am 19 Nov. 2016
Kommentiert: samudra s am 13 Mai 2019
I am using Matlab to call an extrenal function. But I don't have any control on the function I am calling. I want Matlab to stop executing the function and return if it takes more than a certain time. Is there any way I can do it from the main function? In the given code, I want the code to skip and continue if 'analyze.run(i);' takes more than 10 minutes.
Thank you
for i=1:10
tic
analyze.run(i);
toc
end
  3 Kommentare
Walter Roberson
Walter Roberson am 13 Mai 2019
The reply I gave still holds.
See also the list of all known possibilities forsstopping a function without its cooperation at https://www.mathworks.com/matlabcentral/answers/460430-world-mystery-how-can-i-stop-all-the-sub-functions-immediately
samudra s
samudra s am 13 Mai 2019
I solved this issue in a simple yet stupid way. I opened another Matlab and in that I ran a code which would check the output file of the other Matlab every five minutes. If there is no update, then it means the first MATLAB failed and then the second one will send me an email. (when my code fails the entire Matlab gets stuck)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 19 Nov. 2016
Bearbeitet: Walter Roberson am 19 Nov. 2016
The only way I know of to control this is to use the Parallel Computing Toolbox and generate a "future" for the execution, using parfeval(). futures can be canceled if they take too long. That is pretty much handled by killing the process executing the future.
You might possibly be able to do something similar with Parallel Computing Toolbox and batch().
There is no method otherwise to place time restrictions without the cooperation of the function being restricted.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by