Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Interrupting a callback function executing a 'while' loop
Date: Thu, 31 Jan 2008 05:12:01 +0000 (UTC)
Organization: Konem Solutions
Lines: 133
Message-ID: <fnrlb1$lji$1@fred.mathworks.com>
References: <fnpbq0$rn4$1@fred.mathworks.com> <fnpm71$daj$1@fred.mathworks.com> <fnqb22$p1c$1@fred.mathworks.com> <fnqjr5$sro$1@fred.mathworks.com>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201756321 22130 172.30.248.38 (31 Jan 2008 05:12:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 31 Jan 2008 05:12:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413701
Xref: news.mathworks.com comp.soft-sys.matlab:448482


"Grace " <gracee@mathworks.com> wrote in message <fnqjr5
$sro$1@fred.mathworks.com>...
> 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 
> > > 
> > > 
> > 
> 

Hello

You have to use this command 
guidata(hObject, handles); in the while loop

while(xxx)
   .
   .
   .
    drawnow;
guidata(hObject, handles);
     if handles.ExitStatus == 1
         break;
    end
end
guidata(hObject, handles);

HTH
Vihang