MATLAB Answers


How do I execute a MATLAB script at a specific time each day?

I tried to schedule a task to run a MATLAB script at a specific time. I went to:
Start -> Programs -> Accesories -> System tools -> Schedule Task
however, this just opens the MATLAB file, does not run it.



2 Answers

Answer by MathWorks Support Team on 18 Oct 2013
 Accepted Answer

In order to schedule a task in Windows Operating System prior to Windows7, that executes a MATLAB file, do the following:
1. Click on Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks -> Add Scheduled Task
2. Choose MATLAB.
3. After you finish setting up the scheduled task, open the task Properties.
4. If there is
specified under "Run:", change it to:
D:\MATLAB.exe -r mfile [-logfile c:\logfile]
mfile is the name of the MATLAB file you want to execute. If you use the option -logfile, then everything that would be outputted to the MATLAB command window will be saved here. You can also put multiple commands there. For example:
D:\MATLAB.exe -r cd('C:\'),mytest,exit -logfile c:\logfile
would change the current directory to C:\ (where the MATLAB file mytest.m lives), run mytest.m and exit MATLAB. The command window output will be saved in C:\logfile.
To schedule MATLAB script on Windows 7 Task Scheduler, perform the following steps:
1) In Task Scheduler, click on "Create Task".
2) Set the Name and Trigger time.
3) In the Actions tab, click "New". The "Action" should be kept as "Start a program".
4) For "Program/script", use "Browse..." to find the MATLAB executable, which should be a value like: "<file:///C:/Program C:\Program> Files\MATLAB\R2011b\bin\matlab.exe".
5) Set arguments to: -r scriptname;quit. It is not required to specify the ‘.m’ extension here.
6) Set the "Start in" value as the directory containing the script file, e.g.:<file:///C:/users/username/Desktop/Folder. C:\users\username\Desktop\Folder.>

  1 Comment

Hi, i followed the steps above. MATLAB starts and loads the .m-file which contains a function, but the function does not start. What do i have to do to get the function started? Thanks for answering!

Sign in to comment.

Answer by Mohit
on 27 Jan 2015

Hi, I do not see an option to choose matlab like you have mentioned above in point 2. Can someone please help?


thanks, I have never created .exe file in matlab so will I need to create one?
thanks, I have never created .exe file in matlab so will I need to create one?
thanks a lot!

Sign in to comment.