I have a script that I run via a timer every 30 minutes -- how do I run this in background?

40 views (last 30 days)
My script runs on a timer every 30 minutes, and I realize I need to run this in background so I can continue to use Matlab for other work. How do I run this timer script in background?

Accepted Answer

Geoff Hayes
Geoff Hayes on 22 Nov 2017
Robert - try creating a function that you can call from the command line. It will instantiate a timer and then periodically (whenever the timer callback fires) will do some work. For example, in a file named timerInBackground.m you could have
function [myTimer] = timerInBackground
myTimer = timer('Name','MyTimer', ...
'Period',30*60, ...
'StartDelay',0, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
function myTimerCallback(hObject, eventdata)
Then call this function from your command window as
myTimer = timerInBackground;
Then every 30 minutes (30*60 seconds) the timer callback will fire and (in this case) print a hello! message to the console window. In the meantime, you can continue with other MATLAB tasks.
Geoff Hayes
Geoff Hayes on 22 Oct 2021
@L try changing the TasksToExecute field to indicate how many times you want the timer callback function to execute.
As for starting the script...you can call it from the command line as well but I'm not sure if that is what you are really looking for.

Sign in to comment.

More Answers (0)


Find more on Programming Utilities 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!