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

5 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 8 Nov. 2011
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.

Weitere Antworten (0)

Kategorien

Mehr zu Scope Variables and Generate Names finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by