Thread Subject: How to return a variable from a callback function

Subject: How to return a variable from a callback function

From: Milind

Date: 14 Aug, 2009 01:27:01

Message: 1 of 2

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?

Subject: How to return a variable from a callback function

From: Steven Lord

Date: 14 Aug, 2009 13:37:57

Message: 2 of 2


"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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
return variable... Sprinceana 22 Aug, 2009 04:44:55
callback function Sprinceana 22 Aug, 2009 04:44:55
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com