Using a class method as timer callback
Show older comments
Hello,
I am trying to use a matlab app designer class method as a timer callback.
Class definition.
classdef S1_Bluetooth_GUI < matlab.apps.AppBase
I have a timer object called 't' as a class property.
properties (Access = private)
t;
end
This is the timer callback method in a gist.
methods (Access = private)
function execAlive(~,~,app)
% Do stuff with 'app', mostly accessing class properties....
end
end
This is the method I am using to register the timer callback. This bit of code is in another member callback that handle component events
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: STARTButton
function STARTButtonPushed(app, event)
app.t = timer('Period', 2 , 'ExecutionMode', 'fixedRate');
app.t.TimerFcn = {@execAlive,app}; % Register timer callback function
end
end
When I execute this, I am getting the error below
Error while evaluating TimerFcn for timer 'timer-6'
Undefined function 'execAlive' for input arguments of type 'timer'.
Not sure what I am doing wrong here, somehow the timer callback isn`t working. I have tried the same by putting the callback in a separate script file and that works, but when I try to add it as a class method it doesn`t. Any help would be much appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!