Path: news.mathworks.com!not-for-mail
From: "Gautam Vallabha" <gautam.vallabha.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Send an interrupt from a GUI
Date: Fri, 11 Jul 2008 19:06:02 +0000 (UTC)
Organization: The MathWorks Inc
Lines: 42
Message-ID: <g58auq$sfr$1@fred.mathworks.com>
References: <g581oe$ic8$1@fred.mathworks.com>
Reply-To: "Gautam Vallabha" <gautam.vallabha.nospam@mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1215803162 29179 172.30.248.35 (11 Jul 2008 19:06:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 11 Jul 2008 19:06:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1056585
Xref: news.mathworks.com comp.soft-sys.matlab:478905



"David Doria" <daviddoria@gmail.com> wrote in message
<g581oe$ic8$1@fred.mathworks.com>...
> I have a GUI with 2 buttons, "GO" and "STOP"
> 
> When I press "GO", a function is called that takes a long
> time to run.  I would like to make it so when I press "STOP"
> the execution is terminated (the same as pressing ctrl+c in
> the command window).  How do you do this?

During your long-running function, periodically check to see
if the "STOP" button has been pressed. Here's an example of
how to do it:

-------------------------
function testAbort

figh = figure;
btn = uicontrol('style', 'pushb', 'string', 'Abort', ...
                'callback', @doAbort);
isAborted = false;

% simulate a long-running computation with PAUSE
for i=1:10
    checkForAbort();
    disp(i); pause(1);
end

%% =====
    function doAbort(h,e)
        isAborted = true;
    end

    function checkForAbort()
        if isAborted, 
            error('Aborted');
        end
    end
end
-------------------------

Gautam