<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415</link>
    <title>MATLAB Central Newsreader - Send an interrupt from a GUI</title>
    <description>Feed for thread: Send an interrupt from a GUI</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 11 Jul 2008 16:29:02 -0400</pubDate>
      <title>Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442517</link>
      <author>David Doria</author>
      <description>I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&lt;br&gt;
When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
the command window).  How do you do this?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Fri, 11 Jul 2008 17:04:46 -0400</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442526</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
David Doria &amp;lt;daviddoria@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&lt;br&gt;
&amp;gt;When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt;time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt;the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt;the command window).  How do you do this?&lt;br&gt;
&lt;br&gt;
You cannot do that: there is no programmed equivilent to&lt;br&gt;
pressing control-c.&lt;br&gt;
&lt;br&gt;
See also the recent thread &quot;COMMAND WINDOW INTERRUPT&quot; of May 27th,&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://groups.google.ca/group/comp.soft-sys.matlab/browse_frm/thread/363221a0a5e915d/858f4ca6d85566ff&quot;&gt;http://groups.google.ca/group/comp.soft-sys.matlab/browse_frm/thread/363221a0a5e915d/858f4ca6d85566ff&lt;/a&gt;&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;For men are prone to go it blind along the calf-paths of the&lt;br&gt;
&amp;nbsp;&amp;nbsp;mind To do what other men have done. They follow in the beaten&lt;br&gt;
&amp;nbsp;&amp;nbsp;track, and out and in, and forth and back, and still their&lt;br&gt;
&amp;nbsp;&amp;nbsp;devious course pursue, to keep the path that others do.&quot; -- Sam Walter Foss</description>
    </item>
    <item>
      <pubDate>Fri, 11 Jul 2008 19:06:02 -0400</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442551</link>
      <author>Gautam Vallabha</author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt; the command window).  How do you do this?&lt;br&gt;
&lt;br&gt;
During your long-running function, periodically check to see&lt;br&gt;
if the &quot;STOP&quot; button has been pressed. Here's an example of&lt;br&gt;
how to do it:&lt;br&gt;
&lt;br&gt;
-------------------------&lt;br&gt;
function testAbort&lt;br&gt;
&lt;br&gt;
figh = figure;&lt;br&gt;
btn = uicontrol('style', 'pushb', 'string', 'Abort', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'callback', @doAbort);&lt;br&gt;
isAborted = false;&lt;br&gt;
&lt;br&gt;
% simulate a long-running computation with PAUSE&lt;br&gt;
for i=1:10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;checkForAbort();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp(i); pause(1);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%% =====&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function doAbort(h,e)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isAborted = true;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function checkForAbort()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if isAborted, &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error('Aborted');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
-------------------------&lt;br&gt;
&lt;br&gt;
Gautam</description>
    </item>
    <item>
      <pubDate>Fri, 11 Jul 2008 19:23:02 -0400</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442560</link>
      <author>David Doria</author>
      <description>Well the problem is more that the loop that you call&lt;br&gt;
&quot;checkForAbort&quot; from is in a separate m file and therefore&lt;br&gt;
wouldn't have access to the button control.  Do you see the&lt;br&gt;
difference?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Dave&lt;br&gt;
&lt;br&gt;
&amp;gt; function testAbort&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; figh = figure;&lt;br&gt;
&amp;gt; btn = uicontrol('style', 'pushb', 'string', 'Abort', ...&lt;br&gt;
&amp;gt;                 'callback', @doAbort);&lt;br&gt;
&amp;gt; isAborted = false;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % simulate a long-running computation with PAUSE&lt;br&gt;
****&lt;br&gt;
longFunction(); %unable to check button status from inside&lt;br&gt;
this function!&lt;br&gt;
***&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %% =====&lt;br&gt;
&amp;gt;     function doAbort(h,e)&lt;br&gt;
&amp;gt;         isAborted = true;&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     function checkForAbort()&lt;br&gt;
&amp;gt;         if isAborted, &lt;br&gt;
&amp;gt;             error('Aborted');&lt;br&gt;
&amp;gt;         end&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; -------------------------&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Gautam&lt;br&gt;
&amp;gt; </description>
    </item>
    <item>
      <pubDate>Fri, 11 Jul 2008 19:29:14 -0400</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442564</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g58bum$9d5$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
David Doria &amp;lt;daviddoria@gmail.com&amp;gt; top-posted:&lt;br&gt;
&lt;br&gt;
Please do not post your reply above what you are commenting on,&lt;br&gt;
as it makes it difficult to hold a conversation.&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; function testAbort&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; figh = figure;&lt;br&gt;
&amp;gt;&amp;gt; btn = uicontrol('style', 'pushb', 'string', 'Abort', ...&lt;br&gt;
&amp;gt;&amp;gt;                 'callback', @doAbort);&lt;br&gt;
&amp;gt;&amp;gt; isAborted = false;&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; % simulate a long-running computation with PAUSE&lt;br&gt;
&amp;gt;****&lt;br&gt;
&amp;gt;longFunction(); %unable to check button status from inside&lt;br&gt;
&amp;gt;this function!&lt;br&gt;
&amp;gt;***&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; %% =====&lt;br&gt;
&amp;gt;&amp;gt;     function doAbort(h,e)&lt;br&gt;
&amp;gt;&amp;gt;         isAborted = true;&lt;br&gt;
&amp;gt;&amp;gt;     end&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt;     function checkForAbort()&lt;br&gt;
&amp;gt;&amp;gt;         if isAborted, &lt;br&gt;
&amp;gt;&amp;gt;             error('Aborted');&lt;br&gt;
&amp;gt;&amp;gt;         end&lt;br&gt;
&amp;gt;&amp;gt;     end&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&lt;br&gt;
&amp;gt;Well the problem is more that the loop that you call&lt;br&gt;
&amp;gt;&quot;checkForAbort&quot; from is in a separate m file and therefore&lt;br&gt;
&amp;gt;wouldn't have access to the button control.  Do you see the&lt;br&gt;
&amp;gt;difference?&lt;br&gt;
&lt;br&gt;
Count the 'end' statements, Dave. Gautam used a nested function.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;I will not approve any plan which is based on the old principle&lt;br&gt;
&amp;nbsp;&amp;nbsp;of build now and repair later.&quot;                   -- Walter Hickle</description>
    </item>
    <item>
      <pubDate>Fri, 11 Jul 2008 21:21:01 -0400</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#442585</link>
      <author>Scott Burnside</author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; time to run.  I would like to make it so when I &lt;br&gt;
press &quot;STOP&quot;&lt;br&gt;
&amp;gt; the execution is terminated (the same as pressing ctrl+c &lt;br&gt;
in&lt;br&gt;
&amp;gt; the command window).  How do you do this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave&lt;br&gt;
&lt;br&gt;
Dave, you can drop this demo code into an m-file and try &lt;br&gt;
it. If your &quot;long running function&quot; is a loop you might be &lt;br&gt;
able to do something similar:&lt;br&gt;
&lt;br&gt;
function rotate_triangle()&lt;br&gt;
axes('units','normalized',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position',[0.1 0.1 0.8 0.8],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'color',[0.5 0.5 0.5],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'NextPlot','replacechildren',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'tag','plot_axes');&lt;br&gt;
hp = plot([1 3 2 1],[2 4 1 2]);&lt;br&gt;
set(hp,'tag','tplot');&lt;br&gt;
xlim([-8 8]);&lt;br&gt;
ylim([-8 8]);&lt;br&gt;
% define rotation button&lt;br&gt;
uicontrol('units','normalized',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'position', [0.42 .925 .15 .05],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'style','push',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'SelectionHighlight','off',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'string','rotate',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'fontweight','bold',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'fontsize', 10,...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'fontname','arial',...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'foregroundcolor',[0 0 0],...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'callback',{@rotate_button},...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'tag','rotate_button');&lt;br&gt;
&lt;br&gt;
function rotate_button(hload,eventdata)&lt;br&gt;
% locate and delete the main figure object&lt;br&gt;
ax = findobj('tag','plot_axes');&lt;br&gt;
hp = findobj('tag','tplot');&lt;br&gt;
hb = findobj('tag','rotate_button');&lt;br&gt;
stop_flag = get(hp,'userdata');&lt;br&gt;
if ~isempty(stop_flag)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if stop_flag == 0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hp,'userdata',1)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hb,'string','rotate');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elseif stop_flag == 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hp,'userdata',0);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hb,'string','stop');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hp,'userdata',0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(hb,'string','stop');&lt;br&gt;
end&lt;br&gt;
t = hgtransform('Parent',ax);&lt;br&gt;
set(hp,'Parent',t)&lt;br&gt;
Rz = eye(4);&lt;br&gt;
for r = 0:.1:2000*pi&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Rz = makehgtform('zrotate',r);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(t,'Matrix',Rz)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;drawnow&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pause(0.01)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stop_flag = get(hp,'userdata');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if stop_flag == 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
return&lt;br&gt;
% end of code&lt;br&gt;
&lt;br&gt;
hth,&lt;br&gt;
Scott</description>
    </item>
    <item>
      <pubDate>Thu, 26 Feb 2009 20:36:01 -0500</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#631156</link>
      <author>Ron </author>
      <description>Hi, here is an easy way:&lt;br&gt;
Fist, in your function that take s along time, set a variable called stopper=0.  In your loop always check to see if it is 0 or 1.  If it is 1, then break.&lt;br&gt;
&lt;br&gt;
In your gui stop button callback, use an&lt;br&gt;
assignin('ws','stopper',1)&lt;br&gt;
&lt;br&gt;
where ws is the workspace of the function (which can be set when you call the function).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;- Ron &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt; the command window).  How do you do this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave</description>
    </item>
    <item>
      <pubDate>Sun, 07 Nov 2010 20:43:03 -0500</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#793849</link>
      <author>shabnam vcdsd</author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt; the command window).  How do you do this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thats exactly my problem.&lt;br&gt;
&lt;br&gt;
When I put a loop and check the button inside this, it consider it as an infinite loop and it doesn't check the button. it  seems that when it is running a function for one button it ingnors all the buttons that are pressd.</description>
    </item>
    <item>
      <pubDate>Wed, 10 Nov 2010 17:43:04 -0500</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#794932</link>
      <author>Michael </author>
      <description>&quot;shabnam vcdsd&quot; &amp;lt;shabnam.koosha@yahoo.com&amp;gt; wrote in message &amp;lt;ib730n$ara$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; &amp;gt; time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt; &amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt; &amp;gt; the command window).  How do you do this?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Dave&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thats exactly my problem.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I put a loop and check the button inside this, it consider it as an infinite loop and it doesn't check the button. it  seems that when it is running a function for one button it ingnors all the buttons that are pressd.&lt;br&gt;
&lt;br&gt;
You may need to make your for loop interruptible. &quot;If theInterruptible property of the object whose callback is executing is on, the callback can be interrupted. However, it is interrupted only when it, or a function it triggers, calls drawnow, figure, getframe, pause, or waitfor. &quot; &lt;a href=&quot;http://www.mathworks.com/help/techdoc/creating_guis/bq61qtj-1.html;jsessionid=Fl9XMhWMCQ6Z9gGWB2fCgHVQyjgFQvzgQdhJDh503Q4QmTLB21Gn!1797083685&quot;&gt;http://www.mathworks.com/help/techdoc/creating_guis/bq61qtj-1.html;jsessionid=Fl9XMhWMCQ6Z9gGWB2fCgHVQyjgFQvzgQdhJDh503Q4QmTLB21Gn!1797083685&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
If you have a huge loop, however, these may slow it down significantly.</description>
    </item>
    <item>
      <pubDate>Wed, 10 Nov 2010 18:03:03 -0500</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#794941</link>
      <author>Michael </author>
      <description>&quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt; time to run.  I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt; the command window).  How do you do this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave&lt;br&gt;
&lt;br&gt;
I had this same problem and here's how I do it:&lt;br&gt;
&lt;br&gt;
Initialize your stop button with this (paste into beginning of PLAY button callback):&lt;br&gt;
set(handles.stopbutton,'UserData',0); &lt;br&gt;
&lt;br&gt;
Then, in your PLAY button callback INSIDE your FOR loop, use this:&lt;br&gt;
pause(0.00001)&lt;br&gt;
if set(handles.stopbutton,'UserData') = 1&lt;br&gt;
&amp;nbsp;break&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
Then, in your STOP button callback use this:&lt;br&gt;
set(handles.stopbutton,'UserData',1); &lt;br&gt;
guidata(hObject, handles);</description>
    </item>
    <item>
      <pubDate>Wed, 10 Nov 2010 19:38:46 -0500</pubDate>
      <title>Re: Send an interrupt from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172415#794971</link>
      <author>Walter Roberson</author>
      <description>On 10-11-10 12:03 PM, Michael wrote:&lt;br&gt;
&amp;gt; &quot;David Doria&quot; &amp;lt;daviddoria@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g581oe$ic8$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; I have a GUI with 2 buttons, &quot;GO&quot; and &quot;STOP&quot;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; When I press &quot;GO&quot;, a function is called that takes a long&lt;br&gt;
&amp;gt;&amp;gt; time to run. I would like to make it so when I press &quot;STOP&quot;&lt;br&gt;
&amp;gt;&amp;gt; the execution is terminated (the same as pressing ctrl+c in&lt;br&gt;
&amp;gt;&amp;gt; the command window). How do you do this?&lt;br&gt;
&lt;br&gt;
&amp;gt; I had this same problem and here's how I do it:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Initialize your stop button with this (paste into beginning of PLAY&lt;br&gt;
&amp;gt; button callback):&lt;br&gt;
&amp;gt; set(handles.stopbutton,'UserData',0);&lt;br&gt;
&amp;gt; Then, in your PLAY button callback INSIDE your FOR loop, use this:&lt;br&gt;
&amp;gt; pause(0.00001)&lt;br&gt;
&lt;br&gt;
You do not need to specify a time for pause. By specifying a time, you make it &lt;br&gt;
wait at least that time, whereas if you do not specify the time, it would &lt;br&gt;
return as soon as it finished checking whether there was anything in the queue.&lt;br&gt;
&lt;br&gt;
&amp;gt; if set(handles.stopbutton,'UserData') = 1&lt;br&gt;
&lt;br&gt;
That should be get() instead of set(), and should be == instead of = .&lt;br&gt;
&lt;br&gt;
&amp;gt; break&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Then, in your STOP button callback use this:&lt;br&gt;
&amp;gt; set(handles.stopbutton,'UserData',1); guidata(hObject, handles);&lt;br&gt;
&lt;br&gt;
You do not need the guidata() call, as you are not changing the value of &lt;br&gt;
anything that is stored in the handles structure. handles.stopbutton will be a &lt;br&gt;
handle (an arbitrary double precision number) that Matlab will use to look &lt;br&gt;
inside its internal tables to find the structure that holds the data &lt;br&gt;
associated with the handle. When you change that structure, the double &lt;br&gt;
precision number used as the reference does not change, so the handles &lt;br&gt;
structure would not need to be updated.</description>
    </item>
  </channel>
</rss>

