Using a class method as timer callback
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!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! 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! timer, callback, class method MATLAB Answers — New Questions