## Accessing Matlab

To use Matlab, you need to load the appropriate module for the version you want to use. To use the default version, use

$ module load matlab

To use a specific version, check which versions are available, then load it explicitly, as in

$ module available matlab ------------ /usr/flux/software/rhel6/Modules/modulefiles ------------ matlab/2010b matlab/2012b matlab/2014a matlab/2012a matlab/2013a matlab/2015b(default) $ module load matlab/2013a

## Notes on using Matlab

### Restricted licenses for some toolboxes

There are three toolboxes that have limited licenses. If you intend to use one of those toolboxes, you must add an additional line to your PBS script that requests a license or licenses. For example, to request 12 of the Matlab Distributed Computing Engine, which is now officially called the Matlab Distributed Computing Server (MDCS), licenses, you would use

#PBS -l gres=MATLAB_Distrib_Comp_Engine:12

For more information, see our web page on Requesting software licenses.

The toolboxes with limited licenses as of 24 May, 2016, are the following.

Toolbox Name | Number of licenses | GRES line |
---|---|---|

Matlab Distributed Computing Engine | 400 | `#PBS -l gres=matlab_distrib_comp_engine:N` |

Neural Network Toolbox | 10 | `#PBS -l gres=neural_network_toolbox:N` |

Partial Differential Equations toolbox | 10 | `#PBS -l gres=ped_toolbox:N` |

Substitute the appropriate number of licenses for `N`

in the above examples. If you are using the `current`

or `flux`

cluster profiles, you should request one MDCS license per processor in your job.

We no longer support the older cluster usage where you put an `mpiLibConf.m`

file into your `~/matlab`

folder. That was used in Matlab up to version 2013a. Please use Matlab 2015b or later instead, in which there are three profiles defined for parallel computing: local, current, and flux.

See the topics in the sidebar to the right for more information about parallel capabilities in Matlab.

## Running Matlab interactively

To run Matlab interactively, you need to give Matlab an option supressing the graphical display. To do so, invoke Matlab with

$ matlab -nodisplay

Use of Matlab on the login nodes should be for short, non-resource-intensive tasks only. There are CPU time limits set on the login nodes, so if you try to use Matlab for something long running, your session may be terminated.

You can submit a PBS interactive job request if you need to work within Matlab interactively. For more information on interactive jobs, see the web page on Torque interactive jobs.

## Matlab in batch

Matlab assumes that files ending with `.m`

are valid Matlab scripts, and it can run those as if they were Matlab commands if the directory containing them is in the Matlab path. Assume that you have a file, `my_script.m`

, that contains Matlab commands you wish to run. To do so, use

$ matlab -nodisplay -r my_script

## Matlab from PBS

A sample PBS script that shows a single-core Matlab job looks like this:

#PBS -N matlab1 #PBS -q flux #PBS -l procs=1,mem=1gb,walltime=24:00:00,qos=flux #PBS -A example_flux #PBS -M uniqname@umich.edu #PBS -m abe #PBS -V cd ${PBS_O_WORKDIR} matlab -nodisplay -r my_script

### Plotting in Batch Sample

Here are some Matlab commands demonstrating how to save a plot to a color `.eps`

file when running in batch mode.

y=[1:100]'; x=rand(100,1); x=sort(x); plot(x,y); % save the plot as x_by_y.eps (encapsulated postscript color) print -depsc x_by_y % you must include an exit command in your Matlab .m file to close % Matlab when your program is complete. exit

Many graphics formats are available, and you can see many more from the Matlab help system with

> help print

Note that your Matlab job will not have any access to a graphical display or terminal, so all of your input must be handled by one `.m`

file (which can call other `.m`

files), and all of your output must be written to either a file or to the standard output stream (what would be the screen, if there were one) by Matlab or saved with the `print`

command. It is slightly faster to write your output to the standard output stream and let PBS capture the results to the job output file. If you send your output to the standard output stream, you can monitor it while it is running using the `qpeek`

command.

## Matlab toolboxes available on Flux

The University of Michigan licenses a bundle that includes Matlab and many toolboxes. To see the current list of toolboxes, please see the ITS web page for Matlab licensing. In addition to the toolboxes included in the University bundle, Flux also has licenses for the Matlab Distributed Computing Server.