MATLAB: How to get the timer object from within the timer’s callbacks, such as ‘TimerFcn’ and ‘StopFcn’


It would be convenient if I could locate the timer that is executing its callbacks from within the callback itself. For example, if I store handle graphics handles to the timer's 'UserData' property, I would like to be able to access them from within the timer's callbacks.

Best Answer

  • By default, the timer function callbacks pass the timer object as the first argument, and the event data associated with the callback as the second argument. Therefore, you always have access to the timer object from within its callback.
    For more information and to see an example of how to define a timer callback, refer to the "Creating Callback Functions" section of the following URL: