How can I abort a long task programmatically?
조회 수: 4 (최근 30일)
이전 댓글 표시
In the application I'm working at, at some point a potentially very long task has to be executed. Essentially, I'm doing a certain number of stepwise linear regressions with a potentially large set of predictors each. Depending on the number of steps and on the possibility to exploit parallel computation, the task can take several minutes (20-30), or, in the worst cases, even hours.
For this reason, I would like to implement a way to stop the execution from end-user command (ideally through a push button).
The single linear regressions are independent and are done through a for (or parfor) loop, hence I read from other posts that there are different ways to force a for loop to stop from external interaction. My point is: if I use a drawnow command (or similar), the queue will be flushed and a hypothetical callback will be evaluated, but if the sub-task represented by a single command within the loop (in this case the stepwiselm function) takes itself a very long time (with 'very' meaning 1 hour, or maybe only 5 minutes), the drawnow command will be executed only at the end of the current iteration, i.e. potentially after quite a long time.
Is there any way (besides the classic and not so elegant Ctrl-C) to force the program to stop? The code is quite simple and, for more clarity, reads like the following:
for i=1:Nreg
% some quick instructions
regression=stepwiselm('some parameters depending on i');
randomVariable{i}=regression;
% some other quick instructions
end
Thank you very much.
댓글 수: 0
답변 (1개)
Matt Sprague
2018년 1월 12일
You could throw an error when the pushbutton is clicked with the "error" function to stop execution. Similar to https://www.mathworks.com/matlabcentral/answers/105999-how-to-stop-a-function
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!