# MATLAB jobs

In order to run MATLAB on Monsoon,you can either run MATLAB an interactive session or a batch script.

### Interactive Session

When using Matlab as an interactive session you will need to utilize X11 forwarding in your shell. To learn how to do this, please visit our page on [X11](<https://rcdata.nau.edu/hpcpub/docs-test/connecting-to-monsoon/x11-forwarding.html>). Once this is done, you will be able to run Matlab by executing the following commands:

```text
 # First, set up your X11 environment/terminal 

[abc123@wind ~] module load matlab

[abc123@wind ~] srun --mem=2000 --pty matlab
```

This is an example job script for running a non-interactive/non-gui MATLAB `.m` file:

### Batch Script

```bash
Matlab.sh
#!/bin/bash
#SBATCH --job-name=myjob1                    # name of your job within Monsoon
#SBATCH --chdir=/scratch/NAUID               # your work directory
#SBATCH --output=/scratch/NAUID/output.txt   # target for text output/errors
#SBATCH --time=20:00                         # 20 min (max run time)
#SBATCH --mem=2000                           # 2000 megabytes (max available mem)
module load matlab
srun matlab -nodisplay -nodesktop -r "run /scratch/NAUID/myjob1.m"
myjob1.m
1+1
1+2^2
3-7
output.txt
< M A T L A B (R) >
Copyright 1984-2019 The MathWorks, Inc.
R2019b (9.7.0.1190202) 64-bit (glnxa64)
August 21, 2019
To get started, type doc.
For product information, visit www.mathworks.com.
ans = 2
ans = 5
ans = -4
```
