Sometimes you don’t want to remain logged on or keep an ssh session open when running a MATLAB job. This guide will show you how to quickly create a script using nohup that will run MATLAB in the background, sending all output to a text file and even emailing you when the job is finished. Please note that this guide requires at least some use of the command line, so go ahead and open up the terminal.
Create the Script
Using VI, VIM, PICO, Emacs, or your favorite plain text editor create a new text file (e.g., runJob) containing the following:
nohup matlab -nodisplay < YOUR_MATLAB_FILE.m > output.txt &
Now you will need to set the permissions on the file to allow execution by entering the following at the prompt.
When you type ./runJob and hit enter the MATLAB file (YOUR_MATLAB_FILE.m) will be executed with any output going to the output.txt file. Now you can log out of the machine and wait for the job to complete. However we can take this one step further by having the MATLAB file email you when the job has completed.
Have MATLAB Email You When Finished
Simply add the following line of code to the end of your MATLAB file
The ! calls the terminal sending an email with the subject ‘finished’ to YOUR_EMAIL_ADDRESS@GMAIL.COM and pwd places the directory of the job in the contents of the email. This way you know which job has completed as well as the server and location of the job.
Enjoy!

Add New Comment
Viewing 4 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)