Code covered by the BSD License  

Highlights from
Soft interrupting of long computer runs

Soft interrupting of long computer runs

by

 

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

test.m
%   TEST    Demo script for testing loop break
%~~~~~~~~~~~~~~~~~~~~~~~~~~
% The demo program
% * Shows how to implement a soft cycle break with possible variable
%   testing without total cycle interruption.
% * Sets interrupt button BREAK in the user's chosen place on screen and
%   initiates the button.
% * Starts a while cycle, in which the function intrpt is placed.
% * Enters testing function intrpt.
%     - If the button has not been not pushed, the function passes through.
%     - If the button has been pushed, the user may operate in keyboard
%       mode for testing. This mode can be interrupted by pushing F5 key.
% * At the end, the program closes the button window and breaks the loop.  
% Required prerequisity:
% Function inp.m    (www.mathworks.com/matlabcentral/fileexchange/9033)

% Miroslav Balda
% miroslav AT balda.cz
% 2012-02-22    v.1.0   basic version

clear all
close all

global FLAG                        %   compulsory control variabledisp()

xy = eval(inp('Button position','[0.94,0.035]'));   %   button position
hB = setbutton(xy(1),xy(2));       %   create button in SW corner of screen
%~~~~~~~~~~~~~~~~~~~~~~~~~~

w = 0;
while 1                            %   An artificial cycle for testing
    fw = sin(w);
    z  = sqrt(w);
    interpt(w,fw,z)                %   transfers variables and tests button 
    %~~~~~~~~~~~~~~
    disp([w,fw,z])
    if FLAG, close(hB); break, end %   close button window and break loop 
    w  = w + pi/8;
end

Contact us