<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258483</link>
    <title>MATLAB Central Newsreader - How to return a variable from a callback function</title>
    <description>Feed for thread: How to return a variable from a 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, 14 Aug 2009 01:27:01 -0400</pubDate>
      <title>How to return a variable from a callback function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258483#673096</link>
      <author>Milind </author>
      <description>Hello, I've a timer object which calls the specified timer function, now my question is how can I return a variable from the callback function. Below is the code:&lt;br&gt;
&lt;br&gt;
a=timer;&lt;br&gt;
set(a,'ExecutionMode','fixedRate');&lt;br&gt;
set(a,'Period',0.001);&lt;br&gt;
a.timerFcn ={'Get3Chan',s,m}&lt;br&gt;
&lt;br&gt;
start(a);&lt;br&gt;
&lt;br&gt;
So, here it calls the function 'Get3Chan'. Now,I want to return a variable from 'Get3Chan' to the main code. How to do this?</description>
    </item>
    <item>
      <pubDate>Fri, 14 Aug 2009 13:37:57 -0400</pubDate>
      <title>Re: How to return a variable from a callback function</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258483#673209</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Milind&quot; &amp;lt;melindmm@yahoo.com&amp;gt; wrote in message &lt;br&gt;
news:h62eh5$f84$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hello, I've a timer object which calls the specified timer function, now &lt;br&gt;
&amp;gt; my question is how can I return a variable from the callback function. &lt;br&gt;
&amp;gt; Below is the code:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; a=timer;&lt;br&gt;
&amp;gt; set(a,'ExecutionMode','fixedRate');&lt;br&gt;
&amp;gt; set(a,'Period',0.001);&lt;br&gt;
&amp;gt; a.timerFcn ={'Get3Chan',s,m}&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; start(a);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; So, here it calls the function 'Get3Chan'. Now,I want to return a variable &lt;br&gt;
&amp;gt; from 'Get3Chan' to the main code. How to do this?&lt;br&gt;
&lt;br&gt;
You can't.  Suppose you set a timer running in a function (storing the timer &lt;br&gt;
object in a figure's UserData or returning it from the function) and then &lt;br&gt;
the function exits before the timerFcn executed.  To what workspace would &lt;br&gt;
you expect the timerFcn to return the variable?&lt;br&gt;
&lt;br&gt;
What you could do is have the timerFcn store the &quot;return value&quot; in the &lt;br&gt;
timer's UserData property, in a figure's UserData property, or in the &lt;br&gt;
application data using SETAPPDATA and have the function that wants to use &lt;br&gt;
that &quot;return value&quot; retrieve it from where it was stored.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
  </channel>
</rss>

