<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803</link>
    <title>MATLAB Central Newsreader - limit callback function?</title>
    <description>Feed for thread: limit callback function?</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, 18 Jul 2008 01:27:01 -0400</pubDate>
      <title>limit callback function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803#443798</link>
      <author>ching l</author>
      <description>is it possible to limit the callback function?&lt;br&gt;
&lt;br&gt;
for example, the gui button can only be pressed for 10&lt;br&gt;
times, then the callback function is not valid anymore after&lt;br&gt;
10 times.&lt;br&gt;
&lt;br&gt;
thanks.</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 02:18:01 -0400</pubDate>
      <title>Re: limit callback function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803#443808</link>
      <author>Rodney Thomson</author>
      <description>&quot;ching l&quot; &amp;lt;chinglnc@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;g5orh5$kc7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; is it possible to limit the callback function?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for example, the gui button can only be pressed for 10&lt;br&gt;
&amp;gt; times, then the callback function is not valid anymore after&lt;br&gt;
&amp;gt; 10 times.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thanks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
You could just set up a field in the handles structure&lt;br&gt;
called count that is initialised to 1 in the OpeningFcn.&lt;br&gt;
Then the button callback becomes:&lt;br&gt;
&lt;br&gt;
% --- Executes on button press in pushbutton1.&lt;br&gt;
function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
% hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
% eventdata  reserved - to be defined in a future version of&lt;br&gt;
MATLAB&lt;br&gt;
% handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;handles = guidata(gcbo);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (handles.count &amp;lt;= 10)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fprintf(1, 'Pressed %d times\n', handles.count);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;handles.count = handles.count + 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;guidata(gcbo, handles);&lt;br&gt;
&lt;br&gt;
%-------------&lt;br&gt;
&lt;br&gt;
Note, the callback is still valid and executed on each&lt;br&gt;
button press, just nothing really happens. However, you can&lt;br&gt;
allow the call back to function as before by resetting the&lt;br&gt;
value in handles.count to 1 by another callback.&lt;br&gt;
&lt;br&gt;
--&lt;br&gt;
&lt;a href=&quot;http://iheartmatlab.blogspot.com&quot;&gt;http://iheartmatlab.blogspot.com&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 10:37:55 -0400</pubDate>
      <title>Re: limit callback function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803#443869</link>
      <author>Titus</author>
      <description>&lt;br&gt;
&quot;Rodney Thomson&quot; &amp;lt;readmore@iheartmatlab.blogspot.com&amp;gt; schrieb im Newsbeitrag &lt;br&gt;
news:g5ougp$hj3$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &quot;ching l&quot; &amp;lt;chinglnc@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g5orh5$kc7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; is it possible to limit the callback function?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; for example, the gui button can only be pressed for 10&lt;br&gt;
&amp;gt;&amp;gt; times, then the callback function is not valid anymore after&lt;br&gt;
&amp;gt;&amp;gt; 10 times.&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;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; You could just set up a field in the handles structure&lt;br&gt;
&amp;gt; called count that is initialised to 1 in the OpeningFcn.&lt;br&gt;
&amp;gt; Then the button callback becomes:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % --- Executes on button press in pushbutton1.&lt;br&gt;
&amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt; % eventdata  reserved - to be defined in a future version of&lt;br&gt;
&amp;gt; MATLAB&lt;br&gt;
&amp;gt; % handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;    handles = guidata(gcbo);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;    if (handles.count &amp;lt;= 10)&lt;br&gt;
&amp;gt;        fprintf(1, 'Pressed %d times\n', handles.count);&lt;br&gt;
&amp;gt;        handles.count = handles.count + 1;&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;    guidata(gcbo, handles);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; %-------------&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Note, the callback is still valid and executed on each&lt;br&gt;
&amp;gt; button press, just nothing really happens. However, you can&lt;br&gt;
&amp;gt; allow the call back to function as before by resetting the&lt;br&gt;
&amp;gt; value in handles.count to 1 by another callback.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; --&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://iheartmatlab.blogspot.com&quot;&gt;http://iheartmatlab.blogspot.com&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
additionally, you may disable the button completely:&lt;br&gt;
when you reach the max count in your callback:&lt;br&gt;
&lt;br&gt;
set(hObject, 'enable', 'off')&lt;br&gt;
&lt;br&gt;
Titus </description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 14:36:01 -0400</pubDate>
      <title>Re: limit callback function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803#443926</link>
      <author>ching l</author>
      <description>&quot;Rodney Thomson&quot; &amp;lt;readmore@iheartmatlab.blogspot.com&amp;gt; wrote&lt;br&gt;
in message &amp;lt;g5ougp$hj3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;ching l&quot; &amp;lt;chinglnc@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;g5orh5$kc7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; is it possible to limit the callback function?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for example, the gui button can only be pressed for 10&lt;br&gt;
&amp;gt; &amp;gt; times, then the callback function is not valid anymore after&lt;br&gt;
&amp;gt; &amp;gt; 10 times.&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; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You could just set up a field in the handles structure&lt;br&gt;
&amp;gt; called count that is initialised to 1 in the OpeningFcn.&lt;br&gt;
&amp;gt; Then the button callback becomes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % --- Executes on button press in pushbutton1.&lt;br&gt;
&amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt; % eventdata  reserved - to be defined in a future version of&lt;br&gt;
&amp;gt; MATLAB&lt;br&gt;
&amp;gt; % handles    structure with handles and user data (see&lt;br&gt;
GUIDATA)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     handles = guidata(gcbo);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     if (handles.count &amp;lt;= 10)&lt;br&gt;
&amp;gt;         fprintf(1, 'Pressed %d times\n', handles.count);&lt;br&gt;
&amp;gt;         handles.count = handles.count + 1;&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt;     &lt;br&gt;
&amp;gt;     guidata(gcbo, handles);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %-------------&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Note, the callback is still valid and executed on each&lt;br&gt;
&amp;gt; button press, just nothing really happens. However, you can&lt;br&gt;
&amp;gt; allow the call back to function as before by resetting the&lt;br&gt;
&amp;gt; value in handles.count to 1 by another callback.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; --&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://iheartmatlab.blogspot.com&quot;&gt;http://iheartmatlab.blogspot.com&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I always have this kind of errors, and it happens again...&lt;br&gt;
What can I do about it?&lt;br&gt;
&lt;br&gt;
??? Reference to non-existent field 'count'.&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; listening&amp;gt;answer_faster_Callback at 110&lt;br&gt;
if(handles.count&amp;lt;=3)&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; gui_mainfcn at 75&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;feval(varargin{:});&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; listening at 42&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gui_mainfcn(gui_State, varargin{:});&lt;br&gt;
&lt;br&gt;
??? Error while evaluating uicontrol Callback.</description>
    </item>
    <item>
      <pubDate>Fri, 18 Jul 2008 15:00:28 -0400</pubDate>
      <title>Re: limit callback function?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172803#443933</link>
      <author>Titus</author>
      <description>&lt;br&gt;
&quot;ching l&quot; &amp;lt;chinglnc@hotmail.com&amp;gt; schrieb im Newsbeitrag &lt;br&gt;
news:g5q9oh$bq6$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &quot;Rodney Thomson&quot; &amp;lt;readmore@iheartmatlab.blogspot.com&amp;gt; wrote&lt;br&gt;
&amp;gt; in message &amp;lt;g5ougp$hj3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; &quot;ching l&quot; &amp;lt;chinglnc@hotmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;gt;&amp;gt; &amp;lt;g5orh5$kc7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; is it possible to limit the callback function?&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; for example, the gui button can only be pressed for 10&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; times, then the callback function is not valid anymore after&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; 10 times.&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt; thanks.&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; You could just set up a field in the handles structure&lt;br&gt;
&amp;gt;&amp;gt; called count that is initialised to 1 in the OpeningFcn.&lt;br&gt;
&amp;gt;&amp;gt; Then the button callback becomes:&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; % --- Executes on button press in pushbutton1.&lt;br&gt;
&amp;gt;&amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt;&amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt;&amp;gt; % eventdata  reserved - to be defined in a future version of&lt;br&gt;
&amp;gt;&amp;gt; MATLAB&lt;br&gt;
&amp;gt;&amp;gt; % handles    structure with handles and user data (see&lt;br&gt;
&amp;gt; GUIDATA)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;     handles = guidata(gcbo);&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;     if (handles.count &amp;lt;= 10)&lt;br&gt;
&amp;gt;&amp;gt;         fprintf(1, 'Pressed %d times\n', handles.count);&lt;br&gt;
&amp;gt;&amp;gt;         handles.count = handles.count + 1;&lt;br&gt;
&amp;gt;&amp;gt;     end&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;     guidata(gcbo, handles);&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; %-------------&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Note, the callback is still valid and executed on each&lt;br&gt;
&amp;gt;&amp;gt; button press, just nothing really happens. However, you can&lt;br&gt;
&amp;gt;&amp;gt; allow the call back to function as before by resetting the&lt;br&gt;
&amp;gt;&amp;gt; value in handles.count to 1 by another callback.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; --&lt;br&gt;
&amp;gt;&amp;gt; &lt;a href=&quot;http://iheartmatlab.blogspot.com&quot;&gt;http://iheartmatlab.blogspot.com&lt;/a&gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I always have this kind of errors, and it happens again...&lt;br&gt;
&amp;gt; What can I do about it?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ??? Reference to non-existent field 'count'.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Error in ==&amp;gt; listening&amp;gt;answer_faster_Callback at 110&lt;br&gt;
&amp;gt; if(handles.count&amp;lt;=3)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Error in ==&amp;gt; gui_mainfcn at 75&lt;br&gt;
&amp;gt;        feval(varargin{:});&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Error in ==&amp;gt; listening at 42&lt;br&gt;
&amp;gt;    gui_mainfcn(gui_State, varargin{:});&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ??? Error while evaluating uicontrol Callback.&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
you oversaw this sentence in the last post of Rodney:&lt;br&gt;
&lt;br&gt;
You could just set up a field in the handles structure&lt;br&gt;
called count that is initialised to 1 in the OpeningFcn.&lt;br&gt;
&lt;br&gt;
This means you should add&lt;br&gt;
handles.count = 1;&lt;br&gt;
in your GUI_OpeningFcn.&lt;br&gt;
&lt;br&gt;
Titus </description>
    </item>
  </channel>
</rss>

