Skip to content


MATLABĀ® combines a desktop environment tuned for iterative analysis and design processes with a programming language that expresses matrix and array mathematics directly. It includes the Live Editor for creating scripts that combine code, output, and formatted text in an executable notebook.

Available versions of MATLAB in ULHPC

To check available versions of MATLAB at ULHPC type module spider matlab. It will list the available versions:


Interactive mode

To open MATLAB in the interactive mode, please follow the following steps:

(eventually) connect to the ULHPC login node with the -X (or -Y) option:

ssh -X iris-cluster   # OR on Mac OS: ssh -Y iris-cluster
ssh -X aion-cluster   # OR on Mac OS: ssh -Y aion-cluster

Then you can reserve an interactive job, for instance with 4 cores. Don't forget to use the --x11 option if you intend to use the GUI.

$ si --x11 -c4

# Load the module MATLAB and needed environment
(node)$ module purge
(node)$ module load math/MATLAB

# Non-Graphical version (CLI)
(node)$ matlab -nodisplay -nosplash
                  < M A T L A B (R) >
        Copyright 1984-2021 The MathWorks, Inc.
        R2021a ( 64-bit (glnxa64)
                   February 17, 2021
To get started, type doc.
For product information, visit
>> version()
ans =
    ' (R2021a)'
# List of installed add-ons
>>  matlab.addons.installedAddons
ans =
  96x4 table
            Name           Version     Enabled    Identifier
    ___________________    ________    _______    __________

    "Mapping Toolbox"      "5.1"        true         "MG"
    "Simulink Test"        "3.4"        true         "SZ"
>> quit()

# To run the GUI version, over X11
(node)$ matlab &

Batch mode

For non-interactive or long executions, MATLAB can be ran in passive or batch mode, reading all commands from an input file (with .m extension) you provide (Ex: inputfile.m) and saving the results into an output file, for instance outputfile.out). You have two ways to proceed:

matlab -nodisplay -nosplash < inputfile.m > outputfile.out
# /!\ IMPORTANT: notice the **missing** '.m' extension on -r !!!
matlab -nodisplay -nosplash -r inputfile -logfile outputfile.out
#!/bin/bash -l
###SBATCH -A <project_name>
#SBATCH --ntasks-per-node 1
#SBATCH -c 1
#SBATCH --time=00:30:00
#SBATCH -p batch

# Load the module MATLAB
module purge
module load math/MATLAB

# second form with CLI options '-r <input>' and '-logfile <output>.out'
srun -c $SLURM_CPUS_PER_TASK matlab -nodisplay -r my_matlab_script -logfile output.out

# example for if you need to have a input parameters for the computations
# matlab_script_serial_file(x,y,z)
srun matlab -nodisplay -r my_matlab_script(2,2,1)' -logfile output.out

# safeguard (!) afterwards
rm -rf $HOME/.matlab
rm -rf $HOME/java*

In matlab, you can create a parallel pool of thread workers on the local computing node by using the parpool function. After you create the pool, parallel pool features, such as parfor or parfeval, run on the workers. With the ThreadPool object, you can interact with the parallel pool.


# example for MATLAB ParFor (matlab_script_parallel_file.m)
parpool('local', str2num(getenv('SLURM_CPUS_PER_TASK'))) % set the default cores
%as number of threads
n = 50;
A = 50;
a = zeros(1,n);
parfor i = 1:n
a(i) = max(abs(eig(rand(A))));
delete(gcp); % you have to delete the parallel region after the work is done

Additional information

To know more information about MATLAB tutorial and documentation, please refer to MATLAB tutorial.


If you find some issues with the instructions above, please report it to us using support ticket.

Last update: April 19, 2024