Effacer les filtres
Effacer les filtres

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

156 vues (au cours des 30 derniers jours)
I tried to schedule a task to run a MATLAB script at a specific time. I went to:
Start -> Programs -> Accessories -> System tools -> Scheduled Tasks
However, this just opens the MATLAB file, does not run it.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 24 Jan 2023
Modifié(e) : MathWorks Support Team le 24 Jan 2023
Schedule a MATLAB task in Windows Operating System prior to Windows 7
  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's "Properties".
  4. If  under "Run" : 
    D:\MATLAB.exe
    is specified, change it to:
    D:\MATLAB.exe -r mfile [-logfile C:\logfile]
    where "mfile" is the name of the MATLAB file you want to execute. If you use the option "-logfile", then any MATLAB Command Window output will be saved in "C:\logfile". You can also define multiple commands, separated by commas or semi-columns. 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" assumably lives), run "mytest.m" and exit MATLAB. The MATLAB Command Window output will be saved in "C:\logfile".
Schedule a MATLAB task in Windows Operating System running Windows 7 or newer
  1. Click on Start -> Task Scheduler
  2. In Task Scheduler, click on "Create Task".
  3. In "General" tab set the "Name" field to the name of the task.
  4.  In the "Triggers" tab click "New" to select the desired trigger time and frequency of the task. Click "Ok" to save the task.
  5.  In the "Actions" tab, click "New". The "Action" should be kept as "Start a program".
  6.  For "Program/script", use "Browse..." to find the MATLAB executable, which should be a value like:
    C:\Program Files\MATLAB\R2011b\bin\matlab.exe
  7. Set arguments to:
    -r scriptname; quit
    It is not required to specify the ".M" extension here.
  8. Set the "Start in" value as the directory containing the script file, e.g.:
    C:\users\username\Desktop\Folder
     Click "Ok" to save your changes.
  9. Click "Ok" to finish and save.
  1 commentaire
Angelo Yeo
Angelo Yeo le 12 Oct 2023
Modifié(e) : Angelo Yeo le 2 Nov 2023
A side note: You cannot use double quote as input arguments for scriptname in step 7 for Task Schdeuler of Win7 or newer. For example, let's say a function is defined in this way:
function strOutput1 = myfun(strInput1, strInput2)
strOutput1 = strInput1 + strInput2;
end
And you want to use the function in the following way:
myfun("foo","bar")
You may want to set the "argument" in the following way, but this would not run the script as expected.
-r myfun("foo","bar");quit
This is because the whole script would be wrapped with double quotes internally.
As a workaround, you need to use single quote as input arguments and change them inside the MATLAB functions.

Connectez-vous pour commenter.

Plus de réponses (1)

Tharikaa Ramesh Kumar
Tharikaa Ramesh Kumar le 11 Juin 2024
Modifié(e) : Tharikaa Ramesh Kumar le 11 Juin 2024
Do you run time-consuming tasks on MATLAB and Simulink? Do you wish you could schedule them and run them in the background, unattended? How do you solve this question today?
MATLAB Product team is very interested to talk to you and learn from your experience. Please participate in this brief survey (6 questions).

Catégories

En savoir plus sur Big Data Processing dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by