Skip to content

MATLAB

MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment and proprietary programming language developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine allowing access to symbolic computing abilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems.

Availability

Software Version Dependent Toolchain Module Load Command
MATLAB 2023a - module load MATLAB/2023a

Software Version Dependent Toolchain Module Load Command
MATLAB 2022a - module load MATLAB/2022a

Application Information, Documentation

The documentation of MATLAB is available at MATLAB Tutorial

Using MATLAB

Serial Job

Sample Batch Script to run MATLAB: matlab-serial.sh
#!/bin/bash
#SBATCH -J test_matlab
#SBATCH --output=%x.%j.out # %x.%j expands to slurm JobName.JobID
#SBATCH --error=%x.%j.err # prints the error message
#SBATCH --partition=general
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --mem-per-cpu=4000M # Maximum allowable mempry per CPU 4G
#SBATCH --qos=standard
#SBATCH --account=PI_ucid # Replace PI_ucid which the NJIT UCID of PI
#SBATCH --time=71:59:59  # D-HH:MM:SS

# Load matlab module
module purge
module load wulver # Load the slurm, easybuild 
module load MATLAB

matlab -nodisplay -nosplash -r test
#!/bin/bash
#SBATCH -J test_matlab
#SBATCH --partition=public
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH - t 30:00

# Load matlab module
module purge
module load MATLAB/2022a

matlab -nodisplay -nosplash -r test
Sample MATLAB script
A = [ 1 2; 3 4]
A.**2

Parallel Job

Single node parallelization

Sample Batch Script to run MATLAB: matlab_parallel.sh
#!/bin/bash
#SBATCH -J test_matlab
#SBATCH --output=%x.%j.out # %x.%j expands to slurm JobName.JobID
#SBATCH --error=%x.%j.err # prints the error message
#SBATCH --partition=general
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=32
#SBATCH --mem-per-cpu=4000M # Maximum allowable mempry per CPU 4G
#SBATCH --qos=standard
#SBATCH --account=PI_ucid # Replace PI_ucid which the NJIT UCID of PI
#SBATCH --time=71:59:59  # D-HH:MM:SS

# Load matlab module
module purge
module load wulver # Load the slurm, easybuild
module load MATLAB

# Run matlab
matlab -nodisplay -nosplash -r 'for_loop; quit'
#!/bin/bash
#SBATCH -J test_matlab
#SBATCH --partition=public
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=32
#SBATCH --time=30:00

# Load matlab module
module purge
module load MATLAB/2022a

# Run matlab
matlab -nodisplay -nosplash -r 'for_loop; quit'
Sample Parallel MATLAB script: for_loop.m
poolobj = parpool('local',32);
fprintf('Number of workers: %g\n', poolobj.NumWorkers);

tic
n = 2000;
A = 500;
a = zeros(n);
parfor i = 1:n
    a(i) = max(abs(eig(rand(A))));
end
toc

Multi node parallelization

If you want to learn how to install a version of MATLAB on your local system and use it to run jobs on Wulver, please see Using Local MATLAB on Wulver