2010-12-03

Running MATLAB without graphic interface

Case 1: Interactive over SSH

Start MATLAB using the command:
matlab -nodisplay -nojvm

Case 2: Just run a MATLAB script over SSH

In this case, you don't even need a MATLAB Prompt to interact with.
matlab -nodisplay -nojvm -r a_code > matlab.out

Your MATLAB program should have the file name a_code.m (you can change it to whatever name you like. But when you tell MATLAB to run it, omit the .m suffix.) The > matlab.out part redirects the output to a file rather than showing on your Linux/Mac OS X terminal. This way is preferred because you have a record on what is happening.

Case 3: Run MATLAB script with input variables over SSH

First, go to the directory containing the MATLAB script that defines the function (or, fancier, add that directory into MATLAB PATH by editing your MATLABPATH environment variable or pathdef.m file). Then, run like this
matlab -nodisplay -nojvm -r "my_function(10)"
Again, you can redirect the output to a file.

You can also write a Shell, Perl or Python script to do so. MATLAB gives an example using Perl at http://www.mathworks.com/help/techdoc/matlab_env/f8-4994.html

Case 4: On Sun Grid Engine (SGE)-powered cluster

Write a job script below and submit it using qsub

#!/bin/sh
#$ -V
#$ -cwd
#$ -S /bin/bash
#$ -N matlab
#$ -o $JOB_NAME.o$JOB_ID
#$ -e $JOB_NAME.e$JOB_ID
#$ -q normal 
#$ -pe fill 12
#$ -P hrothgar
matlab -nodisplay -nojvm -r a_code > matlab.out

Your MATLAB program should have the file name a_code.m.

For more options on starting MATLAB, please refer to its official doc at
http://www.mathworks.com/help/techdoc/ref/matlabunix.html

No comments: