MATLAB Answers


Tic Toc callback problem

Asked by chris
on 18 Apr 2013

I have a callback function in my code. I have tried to time from outside the callback function to a point within the callback function using the tic toc function. But it doesn't bring in the tic time into the callback function. How can i do this . I have heard about a function called global can bring variables into a callback but i have not managed to get it done with tic toc? Thanks :)



No products are associated with this question.

2 Answers

Answer by Image Analyst
on 18 Apr 2013

Yes. Look at the documentation for tic. Anywhere in your m-file:

global tic;
tic1 = tic;

Then in your callback code

global tic1;
elapsedTime = toc(tic1);

You can have multiple "Tic"s running simultaneously.

  1 Comment

on 18 Apr 2013

Ok thanks a lot i'll try this later

Answer by per isakson
on 18 Apr 2013

Your question is vague. Hint:


    global et
           'Callback', @the_callback_function


    function the_callback_function( ... )
        global et
        ... some code
        et = toc;

  1 Comment

on 18 Apr 2013

What i mean is tic is outside the callback function , then the toc part is within the callback . Is it possible to do this without affecting the accuracy? Thanks a lot .

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!