Instructions for Using MATLAB Software
MATLAB is a software platform for analyzing and designing systems, primarily for numerical computing. It supports matrix manipulation, data visualization, algorithm development, user interface creation, and more.
Programs written in MATLAB can use libraries written in C, C++, Java, and Fortran. Developed by MathWorks, read here.
License
MATLAB is licensed software. HPC Vega provides a Standard Concurrent license intended for simultaneous use by multiple users.
- MATLAB (200 licenses available)
- MATLAB Parallel Server (4000 licenses available)
Academic users may freely use MATLAB on HPC Vega. Commercial users must provide their own license. For more information, contact support@sling.si.
Alternative: Using Your Own License
An alternative option for using your own license is supported. To use your own license, export the environment variable pointing to the license file.
export MLM_LICENSE_FILE=/path/to/license.dat
MATLAB is available on HPC Vega as a module. Load it with:
module load matlab
Ways to Run MATLAB Applications
Running MATLAB from the Command Line
The simplest way to run MATLAB is from the command line. After loading the MATLAB module, start MATLAB in terminal mode with:
matlab -nodisplay
This command starts MATLAB without the graphical user interface (GUI). Once launched, a MATLAB terminal prompt appears where MATLAB commands can be entered directly. For example:
>> disp('Hello from MATLAB!')
Hello from MATLAB!
Exit the MATLAB command line using the exit command.
Running MATLAB Scripts from the Command Line
To execute a MATLAB script directly from the command line, use:
matlab -batch "run('matlabtest.m')"
If your script generates plots that you would like to display during execution, run it using:
matlab -nodesktop -nosplash -r "run('matlabtest.m')"
An example script that generates a plot can be downloaded here. Running the command above should produce a graph similar to the one shown below:

Launching the MATLAB Graphical User Interface (GUI)
MATLAB can also be used through its graphical user interface (GUI). To use the GUI, X11 forwarding must be enabled.
The easiest way to verify this is by checking the value of:
echo $DISPLAY
If no value is returned, X11 forwarding is not configured correctly.
To configure X11 forwarding, follow the instructions here.
Start the graphical interface using:
matlab -display Xdisplay
Replace Xdisplay with the value returned by echo $DISPLAY (for example: matlab -display localhost:10.0).
If launched successfully, the MATLAB graphical interface will open, allowing you to work in the same way as on a personal computer.
Running MATLAB Scripts Through Slurm
For longer computations, we recommend using the Slurm workload manager. In this case, MATLAB runs inside a Slurm job on a compute node rather than directly on the login node.
To submit a job, prepare an SBATCH script such as:
#!/bin/bash
#SBATCH --job-name=matlab-test
#SBATCH --time=00:05:00
#SBATCH --partition=cpu
#SBATCH --nodes=1
#SBATCH --mem=4G
#SBATCH --cpus-per-task=8
module load matlab
matlab -batch "run('matlabtest.m')"
where matlabscript.m represents the MATLAB script to be executed.
The input MATLAB file must have the .m extension. Output will be written to slurm-<jobid>.log.
For additional information about MATLAB commands, load the module on a login node and review the help section:
matlab -h
Example Apptainer Job
Apptainer containers are intended for users who wish to use their own MATLAB license. This approach allows MATLAB to run inside a container, independently of the system-wide MATLAB installation available on Vega.
Example SBATCH script for running a MATLAB program inside a container:
#!/bin/bash
#SBATCH --job-name=matlab-test
#SBATCH --time=00:05:00
#SBATCH --partition=cpu
#SBATCH --nodes=1
#SBATCH --mem=4G
#SBATCH --cpus-per-task=8
apptainer exec /ceph/hpc/software/containers/singularity/images/matlab-<version>.sif matlab -batch matlabscript
Example of Scaling MATLAB Code for Parallel Execution
Learn more about running parallel MATLAB workloads from your local desktop environment here.
Example of Submitting Jobs with ARC
First, you will need an .xrsl file specifying the computing resources required for the job. The example below also includes two input files.
&
(count = 8)
(countpernode = 1)
(jobname = matlab-test)
(inputfiles =
("matlabscript.sh" "")
("matlabscript.m" "")
)
(executable = matlabscript.sh)
(outputfiles = ("example.out" ""))
(stdout=example.log)
(join=yes)
(gmlog=log)
(memory=8000)
(walltime="5 minutes")
Example matlabscript.sh:
#!/bin/bash
# Prepare environment
. /ceph/hpc/software/cvmfs_env.sh
# Load module
module --ignore-cache load matlab
# Run script
matlab -batch matlabscript
For additional examples, such as matlabscript.m, refer to the official documentation.
Documentation
- MATLAB User Documentation: https://www.mathworks.com/help/matlab/
- MATLAB Basic Functions Reference: https://www.mathworks.com/content/dam/mathworks/fact-sheet/matlab-basic-functions-reference.pdf
- MATLAB Examples: https://www.mathworks.com/help/examples.html