Running Matlab Jobs
Quickstart: Matlab
Build a container with Matlab & toolboxes installed inside:
 How to build your own container
 Example container recipes for Matlab
 Use your container in your HTC jobs
Note: Because Matlab is a licensed software, you must add the following line to your submit file:
concurrency_limits = MATLAB:1
Failure to do so may cause your or other users’ jobs to fail to obtain a license from the license server.
More information
CHTC has a site license for Matlab that allows for up to 10,000 jobs to run at any given time across all CHTC users.
Hence the requirement for adding the line concurrency_limits = MATLAB:1
to your submit files, so that HTCondor can keep track of which jobs are using or will use a license.
Following the instructions above, you are able to install a variety of Matlab Toolboxes when building the container. The Toolboxes available for each supported version of Matlab are described here: https://github.com/mathworksrefarch/matlabdockerfile/blob/main/mpminputfiles/. Navigate to the text file for the version of interest, and look at the section named “INSTALL PRODUCTS”. The example recipes linked above provide instructions on how to specify the packages you want to install when building the container.
Executable
When using the Matlab container, we recommend the following process for executing your Matlab commands in an HTCondor job:

Put your Matlab commands in a
.m
script. For this example, we’ll call itmyscript.m
. 
Create the file
runmatlab.sh
with the following contents:#!/bin/bash matlab batch "myscript"
Note that in the script, the
.m
extension has been dropped from the file name (uses"myscript"
instead of"myscript.m"
). 
In your submit file, set the
.sh
script as the executable and list the.m
file to be transferred:executable = runmatlab.sh transfer_input_files = myscript.m
Arguments
You can pass arguments from your submit file to your Matlab code via your executable .sh
and the matlab batch
command.
Arguments in your submit file are accessible inside your executable .sh
script with the syntax ${n}
, where n
is the nth value passed in the arguments line.
You can use this syntax inside of the matlab batch
command.
For example, if your Matlab script (myscript.m
) is expecting a variable foo
, you can add foo=${1}
before calling myscript
:
#!/bin/bash
matlab batch "foo=${1};myscript"
This will use the first argument from the submit file to define the Matlab variable foo
.
By default, such values are read in by Matlab as numeric values (or as a Matlab function/variable that evaluates to a numeric function).
If you want Matlab to read in the argument as a string, you need to add apostrophes around the value, like this:
#!/bin/bash
matlab batch "foo=${1};bar='${2}';myscript"
Here, the value of bar
is defined as the second argument from the submit file, and will be identified by Matlab as a string because it’s wrapped in apostrophes ('${2}'
).
If you have defined your script to act as a function, you can call the function directly and pass the arguments directly as well.
For example, if you have constructed your myscript.m
as a function, then you can do
#!/bin/bash
matlab batch "myscript(${1}, ${2})"
Again, by default Matlab will interpret these value of these variables as numeric values, unless you wrap the argument in apostrophes as described above.