Soft interrupting of long computer runs
Solutions of iterative tasks take sometimes much longer time than expected. There are two possibilities how to solve the issue, either to wait until the program finishes the task, or to interrupt the computer run. Both alternatives are unpleasant.
In the first case, there is rather high uncertainty either how much time the computation could take, or whether it has entered an infinite loop. In the second case, not always it is possible to stop the run by pushing Ctrl+C. Then, the system task manager should be started and the whole MATLAB be suspended. Both alternatives are painful.
There are several functions in FEX that enable to escape from cycling of a program. This contribution is yet another one, based on Roni Peer's contribution (http://www.mathworks.com/matlabcentral/fileexchange/35114).
The submitted contribution contains:
- demo file test.m as a sample of real program structure,
- function setbutton.m for creating BREAK button figure window, and
- function iterpt.m.
All modules are interconnected via global variable FLAG.
The function setbutton.m should be called outside a cycle before iterations or critical cycle starts. It creates a small figure window with a button BREAK on the user defined place of screen.
The function interpt should be inserted in a critical place of iterations. Normally, it is passed through without any slowing down. However, as soon as the function interpt be entered after the BREAK button be pushed, the execution is caught in the function, names of transfered variables are displayed and the program enters the keyboard mode. The user may enter any command from the keyboard. He can display values of the variables either step by step, or, if they were of the same kind in one go by the command disp([varargin{:}]).
The keyboard mode can be interrupted by pushing the function key F5.
The prompt "CONTINUE = yes => " is dispayed and the user decides whether to accept the offer by pushing the ENTER key and continue, or make a hard interrupt by pushing any other key followed by ENTER. In both case the program returns from the function interpt back, where the user can decide what to do. Normally, he tests the global variable FLAG , and suspends the program by a cycle break. Alternatively, he can change iteration conditions and continue in looping.
In both case, the MATLAB environment remains alive with all variables in the workspace.
Cite As
Miroslav Balda (2024). Soft interrupting of long computer runs (https://www.mathworks.com/matlabcentral/fileexchange/35323-soft-interrupting-of-long-computer-runs), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Acknowledgements
Inspired by: Pause a long MATLAB run with a simple click.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |