% Program: print_figure.m
% 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
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.,
print_figure.run, it is submitted to the queue with
Upon job completion the file "out.png" is generated in the work directory.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at Attribution.