Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to return a variable from a callback function
Date: Fri, 14 Aug 2009 09:37:57 -0400
Organization: The MathWorks, Inc.
Lines: 32
Message-ID: <h63pbh$5fe$1@fred.mathworks.com>
References: <h62eh5$f84$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1250257073 5614 172.31.44.65 (14 Aug 2009 13:37:53 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Aug 2009 13:37:53 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:563403



"Milind" <melindmm@yahoo.com> wrote in message 
news:h62eh5$f84$1@fred.mathworks.com...
> 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:
>
> a=timer;
> set(a,'ExecutionMode','fixedRate');
> set(a,'Period',0.001);
> a.timerFcn ={'Get3Chan',s,m}
>
> start(a);
>
> So, here it calls the function 'Get3Chan'. Now,I want to return a variable 
> from 'Get3Chan' to the main code. How to do this?

You can't.  Suppose you set a timer running in a function (storing the timer 
object in a figure's UserData or returning it from the function) and then 
the function exits before the timerFcn executed.  To what workspace would 
you expect the timerFcn to return the variable?

What you could do is have the timerFcn store the "return value" in the 
timer's UserData property, in a figure's UserData property, or in the 
application data using SETAPPDATA and have the function that wants to use 
that "return value" retrieve it from where it was stored.

-- 
Steve Lord
slord@mathworks.com