Interactive Matlab / SPM Processing

We currently have the following versions of Matlab running on the PBIC Cluster:

  • Matlab 2007b
  • Matlab 2009b    (default version)
  • Matlab 2012b
  • matlab 2013a
  • matlab 2014b
  • matlab 2015b
  • matlab 2019a


To set the version of Matlab you wish to use please run the following command to make you selection:

If you are running matlab on the workstation in the Brain Imaging Lab (BIL) please enter the following:


If you are running matlab while connected to PBIC please enter the following:



To start matlab type:


in a new terminal window. A number of events will then happen. Firstly, the cluster will automatically find the most lightly loaded cluster node on which to run matlab. Secondly, it will then try and log you in to this node. You will be prompted to reenter your password. This will look something like:

pch@pbic $ matlab
Your job 143712 ("QLOGIN") has been submitted
waiting for interactive job to be scheduled ...
Your interactive job 143712 has been successfully scheduled.
Establishing /usr/sge/default/common/matlab_wrapper  session to host ...'s password: [enter password]

You will then be logged into the cluster node. Finally, matlab will automatically start up. You are then free to run Matlab/SPM interactively as you wish.

However, please do not run excessive numbers of interactive Matlab sessions as there is a finite number of cluster nodes available to run Matlab on and these are shared for all users in the School. The cluster nodes are also monitored and any excessive usage will be noted. If you need to run a great deal of Matlab/SPM processing, a better way forward is to create batch jobs and to submit these to the cluster (see below).


Non-interactive MATLAB


Batch Matlab / SPM Processing

Redundant instances of the Graphical User Interface (GUI) of  MATLAB sub-optimally use cluster resources. These multiple instances of real time priority GUIs make the cluster appear to perform sluggishly i.e. the cluster has limited resources for interaction, being optimised for the actual tasks of analysis.

The following guide allows you to perform multiple simultaneous MATLAB analyses from the command line using the Sun Grid Engine (sge).  You are encouraged to use this for submitting all analyses and we will actively prune multiple tasks using the interactive MATLAB GUI when warranted.

Below is a sample shell script file one can use to run an example MATLAB script (mymatjob.m) on the cluster.

First; Create the bleow text file using your favourite text editor and name it mymatjob.qsub.  You should only need to edit the final line. This file can reside anywhere, but is placed most sensible where you would run a MATLAB analysis script from e.g. /projects/buicXXX/AnalysisFolder/

# mymatjob.qsub
# Sample shell script to run a MATLAB job under the Sun Grid Engine (sge)
#  Note, this shell script must be executable (i.e. chmod a+rx mymatjob.qsub)
# The following #$ statements are sge Directives i.e. variables
# Name the job mymatjob
#$  -N mymatjob
#   Enter sge parameter for job time limit
#$ -l h_cpu=200:0:0
#$ -l h_cpu=400:0:0
# Choose which version of MATLAB, and the location of your script.
# In this example we use MATLAB2015B – i.e. matlabcluster_2015b
# using ‘matlab_cluster’ is the default, and invokes 2009B

matlab2015b_cluster -nojvm -nodisplay -nosplash < /projects/buicXXX/AnalysisFolder/mymatjob.m

Where mymatjob.m is a MATLAB file we are about to create, containing your MATLAB or SPM code.  After creating mymatjob.qsub  make it executable by executing this command in the terminal;

chmod a+rx mymatjob.qsub

mymatjob.qsub invokes a MATLAB script e.g; /projects/buicXXX/AnalysisFolder/mymatjob.m.  You need to make sure all MATLAB paths required for execution of your analyses are added to the path.  MATLAB  will be run with No Java, No Desktop – which means GUI popups et cetera will be supressed/cause crashes and the textual output will go to a file rather than a MATLAB window. There can be no interactive elements required wihin the submitted MATLAB scripts

% mymatjob.m example file

cd('/projects/buicXXX/AnalysisFolder’); % Analysis folder

addpath(pwd); %Add this folder to the Path

%% example analysis script

palm -i all_L1_skeletonised.nii -m mean_FA_skeleton_mask.nii -d design_two_sample_ttest_NOIQ_Age.mat -t design_two_sample_ttest_NOIQ_Age.con -eb block.csv -vg auto -n 10000 -T -C 3.1 -fdr -o two_sample_ad_NOIQ_age_10000 –logp

With both mymatjob.qsub and .m created you are ready to submit this job. Type the following command into the terminal:

qsub -q matlab_batch.q /projects/buicXXX/mymatjob.m

The qsub command will run your MATLAB job on the most lightly loaded node (that can run MATLAB). To check the status of your job(s) type, in a terminal window:


You will see a list of tasks with an associated numerical identifier.

The output of your jobs will not be echoed to a MATLAB window as per normal, but instead to two text files created in your Home Folder; in files name

jobname.oxxxx and jobname.exxxx

where jobname is the name from the #$ -N jobname command above, and xxxx is the job numerical identifier.

If your qstat comes back empty – then your code has crashed and  jobname.exxxx will be non-0k. Use your favourite text editor to see what issues have arisen.  Tasks will silently fail/succeed – you must seek such information.

As your code executes jobname.oxxxx will grow in size. You can see a live update of the text output of your job by executing this command, in your home folder, in the terminal:

jobname.oxxxx and jobname.exxxx

This will update live as disp and fprintf commands are executed, capturing all the information that would normally be echoed to the Command Window in MATLAB.

For multiple simultaneous analysis simply undertake all the above steps and fashion a second mytaskname.qsub and mytaskname.m file.