How to run Matlab programs in batch mode on the cluster?
Here are the steps for running Matlab in batch mode:
1. save your Matlab commands in a m-file (say, example.m), as follows:
x = 1:4
disp('this is a test')
plot(x,x)
print -deps /path/to/myplot % save the plot as a postscript file at /path/to/myplot.eps
exit % need this for batch mode
2. then call Matlab from within your PBS script as follows:
#!/bin/sh
#PBS -j oe
#PBS -o matlab-example.out
#PBS -m abe
#PBS -M narora@princeton.edu
unset DISPLAY
matlab < $PBS_O_WORKDIR/example.m
Here, matlab takes input from your m-file created above and sends all command window output to the file matlab-example.out Detailed documentation for this can be found here
