MATLAB: How to implement a timer in AppDesigner

appdesignertimer

Hello,
i hope somebody may can help me. I try to implement a timer (periodic 2ms) in Matlab AppDesiner (2016a). When the timer executes i will read data from a USB buffer. My problem is to set up the timer correctly so that the callback function TimerFcn is started.
Thanks
Best Regards Hannes

Best Answer

There are a few ways of doing this, but here's one way...
1) Create a custom property called myTimer, which would look like this:
properties (Access = private)
myTimer % Description
end
2) In your startup function, create your timer object, assign it to the custom property, and configure your timer callback. Something like this:
app.myTimer = timer('Period',2,...
'ExecutionMode', 'fixedSpacing', ...
'TasksToExecute', Inf);
app.myTimer.TimerFcn = @(x,y)disp('do something');
Note, if you need to wire your timer callback to a function inside your app, the TimerFcn syntax would be a little different. You can reference this post for a few options for that: