Main Content Region



The college has a site license for Matlab.

Running Matlab Interactively

There are a number of versions of Matlab installed on the TCHPC clusters.

To run Matlab interactively on the TCHPC clusters, you must:

  • log in via SSH
  • obtain an interactive allocation on the cluster
  • load the modules:
    • To load the main version of matlab (currently version R2015aSP1) type module load apps matlab
    • To load the version of matlab available to TCIN users, type module load tcin matlab
  • and then run it from the command-line: matlab

Running Matlab through the Batch System

To submit a batch Matlab job on the TCHPC clusters, you must:

  • create a text file containing the commands you wish to run, e.g. "test.m" (see below for an example)
  • the .m matlab file must include exit as the last line, to make sure that matlab exits correctly
  • create a SLURM batch submission script (see below for an example)
  • submit it to the queue
  • when the job has finished, check the output

Sample Matlab File

This file (called "test.m") simply creates a matrix and prints it out.
% comments in the matlab file start with a percent sign

% create the matrix
A = rand(4,4);

% print it out

% NB: include this line at the end

Sample SLURM Script

This loads the relevant modules, calls Matlab with the given instructions, and redirects the output to a file called "output.txt".

#SBATCH -n 1		# number of cores
#SBATCH -p compute	# compute queue
#SBATCH -t 00:10:00	# time (ddd-hh:mm:ss)
#SBATCH -J matlab       # job name

# load up the correct modules

. /etc/profile.d/
module load apps matlab

# call matlab non-interactively

matlab -nodisplay 

Alternatives to Matlab

There are a few free and open-source alternatives to Matlab such as Scilab and Octave. These programs are available on a selection of the machines that TCHPC maintain.

Adding additional folders/directories to the Matlab PATH

There are two ways to permanently add folders to the Matlab PATH on a Unix system:

  1. Create a file called "startup.m" in your home directory, and add folders using the "addpath" command. For example:
    • addpath /home/users/myusername/mytools
  2. Set the environment variable "MATLABPATH" in your ~/.bashrc file. For example (assuming the bash shell):
    • export MATLABPATH=/home/users/myusername/mytools

Note: if you just wish to add a folder as a once-off, you can just call the addpath /home/users/myusername/mytools function from within Matlab.