MATLAB
MATLAB GUI
To use the MATLAB GUI, we recommend our web portal, Open OnDemand. Once logged in, click MATLAB pinned on the dashboard, or select "MATLAB" from the "Interactive Apps" list.
Command Line MATLAB
Find MATLAB
Run one of the commands below, which will list available versions and the corresponding module files:
module avail matlab
Load the appropriate module file. For example, to run version R2021a:
module load MATLAB/2021a
The module load command sets up your environment, including the PATH to find the proper version of the MATLAB program.
Run MATLAB
Warning
If you try to run MATLAB on a login node, it will likely crash. Instead, launch it in an interactive or batch job (see below).
Interactive Job (without a GUI)
To run MATLAB interactively, you need to create an interactive session on a compute node.
You could start an interactive session using 4 cores, 16GiB of RAM for 4 hours with:
salloc -c 4 --mem 16G -t 4:00:00
Once your interactive session starts, you can load the appropriate module file and start MATLAB
module load MATLAB/2021a
# launch the MATLAB command line prompt
maltab -nodisplay
# launch a script on the command line
matlab -nodisplay < runscript.m
See our Slurm documentation for more detailed information on requesting resources for interactive jobs.
Batch Mode (without a GUI)
Create a batch script with the resource requests appropriate to your MATLAB function(s) and script(s). In it load the MATLAB module version you want, then run matlab
with the -b
option and your function/script name. Here is an example that requests 4 CPUs and 18GiB of memory for 8 hours:
#!/bin/bash
#SBATCH --job-name myjob
#SBATCH --cpus-per-task 4
#SBATCH --mem 18G
#SBATCH -t 8:00:00
module load MATLAB/2021a
# assuming you have your_script.m in the current directory
matlab -batch "your_script"
# if using MATLAB older than R2019a
# matlab -nojvm -nodisplay -nosplash < your_script.m
Using More than 12 Cores with MATLAB
In MATLAB, 12 workers is a poorly documented default limit (seemingly for historical reasons) when setting up the parallel environment. You can override it by explicitly setting up your parpool before calling parfor or other parallel functions.
parpool(feature('NumCores'));