May 31st & June 1st are university holidays.
Next monthly maintenance June 7th 7am-11am - [Details]
Annual MGHPCC Power Shutdown Aug 9-12 [Details and Schedule]
STATUS PAGE No known issues.

Search Docs by Keyword

MATLAB Figures in a Batch Mode

This web-page illustrates how to create MATLAB figures in a batch-mode (without a GUI) on the Odyssey cluster. This is especially useful if you would like to do your computations and post-processing all together in a consistent computing environment. Below is an example function which generates data, creates a figure, and saves it as a file on the cluster:

% Program: print_figure.m
% Usage:
% matlab -nodesktop -nodisplay -nosplash -r “print_figure(‘file_name’,’file_format’);exit”
function [] = print_figure( outfile, file_format )
disp(‘A simple test to illustrate generating figures in a batch mode.’);
x = 0:.1:1;
A = exp(x);

The specific example saves the figure as a PNG (24-bit) image. For complete list of available image formats, please refer to the official MATLAB documentation.
Here is an example SLURM batch-job submission script for sending the job to the queue:

#SBATCH -J print_figure
#SBATCH -o print_figure.out
#SBATCH -e print_figure.err
#SBATCH -p serial_requeue
#SBATCH -n 1
#SBATCH -t 30
#SBATCH –mem=2000
matlab -nodesktop -nodisplay -nosplash -r “print_figure(‘out’,’-dpng’);exit”

Please, notice the options -nodesktop -nodisplay -nosplash on the MATLAB command line. These reassure the figure is generated properly without the GUI. If you name this script, e.g.,, it is submitted to the queue with


Upon job completion the file “out.png” is generated in the work directory.

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Need help?
© The President and Fellows of Harvard College
Except where otherwise noted, this content is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.