I am trying to run a Matlab script every day using the Windows Task Scheduler. I am using Matlab R2011b 64-bit, and Windows 7. According to Matlab, a script myfile.m can be run from the command line as follows:

matlab -r myfile

On my old computer (32 bit XP), I could execute the script by putting the following in the 'Run' window of the XP Task Scheduler:

C:\PROGRA~1\MATLAB\R2010a\bin\matlab.exe -r myfile;quit

But when I enter the following on my new computer's Windows 7 Task Scheduler, the Task stays as Queued and does not run:

C:\PROGRA~1\MATLAB\R2011b\bin\matlab.exe -r myfile;quit

Just discovered that it can run if I choose 'Run only if user is logged on', but I need it to 'Run whether user is logged in or not'. Under the Properties of matlab.exe it says that administrators have Full Control, and I am presently logged in with an administrator account, so can't figure out what the problem is. Any suggestions? Alternatively is it possible to run the XP version of Task Scheduler on Windows 7, since I never ran into these issues?

  • Does the command work from a normal command prompt? If not, what about a prompt run as administrator? – sblair Oct 4 '11 at 15:02
  • Yes, it works fine from the command prompt. – KAE Oct 4 '11 at 15:18

It works for me using the following procedure:

  1. In Task Scheduler, click on "Create Task...".
  2. Set the name and trigger time, etc.
  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 set a value like: "C:\Program Files\MATLAB\R2011a\bin\matlab.exe".
  5. Set arguments to: -r scriptname;quit. You do not need the .m if that's the script extension.
  6. Set the "Start in" value as the directory containing the script file, e.g.: C:\Folder.
  • 1
    Yes, all this works fine, thanks. Turns out the source of my problems was permissions (must choose 'Run only when user is logged on' or it won't work.) – KAE Oct 4 '11 at 18:10

I suggest using the real directory name instead of PROGRA~1. This is only for FAT backwards compatibility.

  • Gets tricky because the full path name must be enclosed in double quotes ("C:\Program Files\MATLAB\R2011b\bin\matlab.exe" -r myfile;quit), and both Win 7 Task Scheduler and Matlab ascribe meanings to the double quotes. Still I'll give it a try. – KAE Oct 4 '11 at 15:20
  • Works fine. The source of my problem has turned out to be permissions: the program only works if I choose 'Run only when user logged on'. – KAE Oct 4 '11 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.