Path: news.mathworks.com!not-for-mail
From: "Grace " <gracee@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Interrupting a callback function executing a 'while' loop
Date: Wed, 30 Jan 2008 19:40:21 +0000 (UTC)
Organization: Johns Hopkins University
Lines: 98
Message-ID: <fnqjr5$sro$1@fred.mathworks.com>
References: <fnpbq0$rn4$1@fred.mathworks.com> <fnpm71$daj$1@fred.mathworks.com> <fnqb22$p1c$1@fred.mathworks.com>
Reply-To: "Grace " <gracee@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 1201722021 29560 172.30.248.35 (30 Jan 2008 19:40:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 30 Jan 2008 19:40:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 629309
Xref: news.mathworks.com comp.soft-sys.matlab:448386


Hi everybody

My program looks like this:

function Main_Fig_OpeningFcn(hObject, eventdata, handles,
varargin)
handles.output = hObject;
guidata(hObject, handles);
handles.StartStatus = 0;
guidata(hObject,handles)
handles.ExitStatus = 0;
guidata(hObject,handles)

function Start_button_Callback(hObject, eventdata, handles)
handles.StartStatus = 1;
guidata(hObject,handles)
while(xxx)
    .
    .
    .
    drawnow;
    if handles.ExitStatus == 1
        break;
    end
end
if handles.ExitStatus == 1
    delete(handles.output);
else
    ...
end

function Exit_button_Callback(hObject, eventdata, handles)
handles.ExitStatus = 1;
guidata(hObject,handles)
if handles.StartStatus == 0
    close all;
end


Could anybody please help me in making the Exit button work.

Thanks in advance.
Grace




"Grace " <gracee@mathworks.com> wrote in message
<fnqb22$p1c$1@fred.mathworks.com>...
> Thanks for the reply. However it doesnt exit (or even change
> the value of handles.pleaseStopNow) until I press the Exit
> button rapidly for 2-3 times.
> 
> Could you suggest what can be wrong.
> 
> Thanks.
> Grace
> 
> 
> "Titus" <titus.edelhofer@mathworks.de> wrote in message
> <fnpm71$daj$1@fred.mathworks.com>...
> > 
> > "Grace " <gracee@mathworks.com> schrieb im Newsbeitrag 
> > news:fnpbq0$rn4$1@fred.mathworks.com...
> > >I have made a GUI which has a 'Start' pushbutton, which
> > > causes a 'while' loop to begin (pretty long loop). I also
> > > have an 'Exit' pushbutton. I have tried many ways but on
> > > pressing the Exit button, I am not able to make the
program
> > > stop running and the GUI to close without any error on
> > > command window.
> > >
> > > Could anyone please help me with that.
> > >
> > > It is kind of urgent.
> > >
> > > Thanks.
> > > Grace
> > >
> > >
> > 
> > Hi,
> > have the exit button set something in the handles
> structure (like 
> > handles.pleaseStopNow = true;) and store it using guidata.
> > In your loop you need to add at the end of the loop:
> > 
> > drawnow; % this allows to be interrupted by exit button
> > handles=guidata(hObject);
> > if handles.pleaseStopNow
> >   % leave the loop
> > end
> > 
> > Titus 
> > 
> > 
>