General information

To use Matlab, you need to load the appropriate module for the version you want to use. The following example shows how to load the default MATLAB module.

$ module load matlab

To use a specific version, check which versions are available with this module command.

$ module spider matlab

Then load the version you want. Please see our page on Lmod for more information on modules. For example, to load Matlab R2020a, you would use

$ module load matlab/R2020a

To run MATLAB at a prompt, simply type

$ matlab

that will start either a text-based interface or the desktop if an appropriate display is defined.

To run a MATLAB script from the the command line, use MATLAB’s -r option, as in this example which runs the Matlab script my_simulation.m from the current directory.

$ matlab -r ./my_simulation

Note that the MATLAB script that you run should have an exit command in it. If your MATLAB program does not contain an exit, when it completes, MATLAB will remain active but idle until all the requested walltime for your job has elapsed.

If your program does not contain an exit, you can supply it on the command line with

matlab -nodisplay -r "./my_simulation ; exit"

and note that the quotes are required because of the semicolon, which would otherwise mark the end of the matlab command and run the exit command in the shell, which will log you out!

If your my_simulation.m script can be invoked with arguments, say the number of iterations and mesh size as the two arguments, you can also pass those on the command line with

matlab -nodisplay -r "./my_simulation(2, 10)"

and again, the quotes are required to keep the parentheses from being interpreted by the shell.

You may run MATLAB on a login node so long as it does not consume a lot of memory or CPU cycles or run for a long time. In general, that means only working with smaller amounts of data and not running programs that do a lot of computing. Running small, test cases to verify syntax and check viability are OK, but you should submit a job for larger and longer running jobs. As a guideline, you should not use more than 4 GB of memory, and your program should not run more than 5–10 minutes without pause.