File Exchange

image thumbnail

Soft interrupting of long computer runs

version 1.0 (6.18 KB) by

Long run of the program can be interrupted without any loss of data in a workspace.

1 Download


View License

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 (

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.

Comments and Ratings (0)

MATLAB Release
MATLAB 7.3 (R2006b)

Inspired by: Pause a long MATLAB run with a simple click.

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video