This enhancement has been incorporated in Release 14 Service Pack 2 (R14SP2).
To run MATLAB in the background, you need to do the following:
1. Redirect the standard input.
2. Redirect the standard output.
3. Eliminate the graphical output.
4. Call MATLAB as a background process.
You may also want to change the process's priority to decrease its effect on total CPU usage.
Here is a simple script written for the UNIX C shell, which demonstrates one way of running MATLAB in the background:
#! /bin/csh -f
# Clear the DISPLAY.
unsetenv DISPLAY # unset DISPLAY for some shells
# Call MATLAB with the appropriate input and output,
# make it immune to hangups and quits using ''nohup'',
# and run it in the background.
nohup matlab -nodisplay -nodesktop -nojvm -nosplash -r $1 > $2 2 > erroroutput &
Save this script in a file called matbg and change its permissions to make it executable. The syntax for calling it is:
matbg <"infile"> <"outfile">
... where is the MATLAB file to be executed, and is the file to which the output will be sent. Errors, if any, will be redirected to the file "erroroutput". If takes input arguments, enclose the function call in double quotes:
matbg "foo(10);quit" <"outfile">
If you are not interested in saving the output, you can specify /dev/null as the second argument.
If you want to change the process's priority, you can use the UNIX command nice in the line which invokes MATLAB. For example, if you wish to change MATLAB's priority to 19, change the appropriate line to the following:
nohup nice -10 matlab -nodisplay -nodesktop -nojvm -nosplash -r $1 > $2 2 > erroroutput &