To use MATLAB, the MATLAB compiler, or standalone executables created with the MATLAB compiler, you must first load the matlab module via the following command:

module add matlab

Using the module’s primary name on its own will result in the defalt version of matlab being used. To see what other versions of matlab are currently available, type:

module avail matlab

See the Using environment modules on the HEC page for more details on the module command.

A sample matlab and batch job script

Matlab code can be executed by calling its main function and optional arguments from within a call to matlab. Consider the following simple function which returns twice the value it receives as an argument, contained in file called twotimes.m:

function twotimes (x)

2 * x

This function can be called with a job script like this:


#SBATCH -p serial
#SBATCH --mem=1G

source /etc/profile
module add matlab/2022a

matlab -singleCompThread -nodisplay -nosplash -r "twotimes (3.1)"

Further Reading

The Matlab Home Page