Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

Technical Solutions

How do I run MATLAB in batch mode on a UNIX machine?


Date Last Modified: 20 Jan 2008
Solution ID:   1-15HNG
Product:   MATLAB
Reported in Release:   R11
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I run MATLAB in batch mode on a UNIX machine?

Problem Description:

I would like to know how to run MATLAB in batch mode on a UNIX machine, and I would also like to suppress all terminal outputs from MATLAB.

Solution:

MATLAB can be run at the command line or in batch mode without terminal output. Here are some examples of how to do this on a UNIX system:

1. Assuming you are using a "C-Shell" (csh) environment, here is a command line example:


% unsetenv DISPLAY
% matlab >&! matlab.out << EOF
>plot(1:10)
>print file
>exit
EOF
%
This produces a PostScript file of plot(1:10) in "file.ps". No screen graphics are produced and all command window output is sent to "matlab.out".

NOTE: In MATLAB 6.5 (R13) there is an issue with headless printing, i.e., when the DISPLAY is unset, which causes the PS file to be created without any plot in it. In order to create "file.ps" that contains a plot you need to add the commands "figure;close" before the PLOT statement:

% unsetenv DISPLAY
% matlab >&! matlab.out << EOF
> figure;close
> plot(1:10)
> print file
> exit
EOF
%

2. To run MATLAB in a batch job you can use the "at" command.

NOTE: Some options for the "at" command are platform specific.

a) Using a "csh" environment, let "atfile.csh" be the batch file you want to run:

unsetenv DISPLAY
matlab >&! matlab.out << EOF
plot(1:10)
print file
exit
EOF
To run the batch file, (For example on the sun4):

% at -c -f atfile.csh now + 1 min
This will run the script, "atfile.csh" 1 minute from now which does the same as in the command line example above.

b) Using an "sh" environment, let "atfile.sh" be the batch file:

unset DISPLAY
matlab > matlab.out 2>&1 << EOF
plot(1:10)
print file
exit
EOF
To run the batch file, (For example on the sun4):

% at -s -f atfile.sh now + 1 min
This will run the script, "atfile.sh" 1 minute from now which also does the same as in the command line example above.

  Provide feedback to help us improve this solution!
Contact support
Print this page