> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MATLAB

To use an interactive MATLAB® session in Domino, you must configure a Compute Environment and interactive Workspace. If your administrators have already configured such an Environment, you can use it by setting your Project to use that Environment.

## Configure a MATLAB Environment in Domino

This topic describes how to create a Compute Environment if it does not already exist. You might need help from a Domino or MATLAB admin.

## Prerequisites

**Network licensing structure for MATLAB**\
You must have a network license to configure the Compute Environment. Domino recommends a network concurrent license. A network-named license might work if the usernames specified in the license matches the usernames in Domino. If you don’t have a network concurrent license, contact your MATLAB license administrator. You can have a single license server or a set of three license servers. The following are examples of how to provide the license server information:

### Method 1

This method requires only the port and host for your license servers. For example, `27000@lic1.customer.com` (and optionally `27000@lic2.customer.com`, `27000@lic3.customer.com`). This is recommended for most cases.

### Method 2

Use this method if you have a `network.lic` file. For example:

```shell theme={null}
SERVER lic1.customer.com 000000000000 27000 SERVER lic2.customer.com 000000000010 27000 SERVER lic3.customer.com 000000000020 27000 USE_SERVER
```

This is recommended only if you have several sets of license servers (and therefore, several license files). For example, you would have separate license servers for MATLAB Parallel Server.

See [Mathworks help](https://www.mathworks.com/matlabcentral/answers/116637-what-are-the-differences-between-the-license-lic-license-dat-network-lic-and-license_info-xml-lic) for more information about the options or talk to your MATLAB license administrator.

**(Optional) Hardware Tiers with the correct GPU drivers**\
To use GPU capabilities, the hardware tier in Domino must have GPU drivers installed that can support the version of MATLAB that you want to use. Use the following to determine compatibility:

* [GPU Support by Release table](https://www.mathworks.com/help/solutions/parallel-computing/gpu-support-by-release.html) which describes the minimum CUDA Toolkit version requirement for each version of MATLAB.

* [CUDA compatibility](https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver) which describes the minimum NVIDIA driver version requirement for each version of the CUDA Toolkit.

The MATLAB base images provided by Domino already have a suitable version of the CUDA Toolkit installed. You must configure the NVIDIA drivers at the Hardware Tier level. If you already have a GPU-enabled hardware tier configured, it is likely that it already has suitable NVIDIA drivers. See the [Troubleshooting section](#faq-and-troubleshooting) for instructions about how to check the driver version during a MATLAB session to verify it is configured correctly.

If you do not have the correct NVIDIA drivers configured on your GPU Hardware Tier, contact your Domino administrator and refer them to the documentation to [configure NVIDIA drivers in EKS](/cloud/admin/platform-configuration/manage-compute-environments/cache-images-in-eks/ami-operations#install-nvidia-docker-20-gpu-amis-only). talk to your Domino administrator. They must install and/or upgrade the NVIDIA drivers, and (if your deployment uses Amazon Web Services) update the executor AMI following a procedure similar to the one for [Creating a new executor AMI](/cloud/admin/platform-configuration/manage-compute-environments/cache-images-in-eks). If you are a Domino administrator looking for guidance on this process, contact your Domino account team or email us at [support@dominodatalab.com](mailto:support@dominodatalab.com).

## Environment setup

If a MATLAB-specific Environment does not already exist in your Domino deployment, you must create one. Read about [Environment Management](/cloud/platform-capabilities/core-concepts/compute-environments/manage-compute-environments) if you aren’t already familiar.

### Choose a base image

When creating a new Environment, choose a base image that has MATLAB installed. The following are the most current options available from Domino.

| Version      | Repo Link                      |
| ------------ | ------------------------------ |
| MATLAB 2021a | `quay.io/domino/matlab:R2021a` |
| MATLAB 2020b | `quay.io/domino/matlab:R2020b` |
| MATLAB 2020a | `quay.io/domino/matlab:R2020a` |
| MATLAB 2019b | `quay.io/domino/matlab:R2019b` |

### Edit the Dockerfile

1. Add the following lines to your **Dockerfile Instructions**, editing the license server information to match your actual license servers.

2. Edit the `MATLAB_VERSION` variable to match the MATLAB version of the base image you chose in the previous step.

3. If you have port and host information for your license servers (recommended method):

   ```bash theme={null}
   # This MATLAB_VERSION variable is used later in persisting Add-ons and preferences
   ENV MATLAB_VERSION='R2019b'
   ENV MLM_LICENSE_FILE=27000@lic1.customer.com,27000@lic2.customer.com,27000@lic3.customer.com
   ```

   Or, if you have multiple license files and you have a `network.lic` file you can adapt this example:

   ```bash theme={null}
   USER root

   ENV MATLAB_VERSION='R2019b'
   # Here we are simply pasting the information in the license file
   # If you have the license file hosted somewhere accessible to Domino, you could instead download it to the same location via wget or similar methods
   RUN mkdir -p /usr/local/MATLAB/$MATLAB_VERSION/licenses &&
       printf "SERVER lic1.customer.com 000000000000 27000
   SERVER lic2.customer.com 000000000010 27000
   SERVER lic3.customer.com 000000000020 27000
   USE_SERVER
   " > /usr/local/MATLAB/$MATLAB_VERSION/licenses/network.lic

   USER ubuntu
   ```

### Add pluggable Workspace tools definition

1. Add the "Pluggable Properties" to the **Properties for Workspaces**.

   These are documented alongside the base image descriptions here: [https://github.com/dominodatalab/Domino\_Base\_Images/tree/master/MATLAB\_Base\_Images](https://github.com/dominodatalab/Domino_Base_Images/tree/master/MATLAB_Base_Images).

   The MATLAB base images are built on top of the [Domino Standard Environment](/cloud/platform-capabilities/core-concepts/compute-environments/manage-compute-environments/2-domino-standard-environments), so you can add the Workspace configurations such as Jupyter or RStudio for those standard Environments also.

For example, if you are using the `quay.io/domino/matlab:r2019b-20200521` base image, add the following lines for the MATLAB Workspace:

```yaml theme={null}
matlab-rdp:
  title: "RDP"
  iconUrl: "https://raw.githubusercontent.com/dominodatalab/partner-resources/main/assets/workspaces/Mathworks/MATLAB/matlab-simulink.png"
  start: [ "/opt/domino/workspaces/matlab/start" ]
  httpProxy:
    port: 8080
    internalPath: "/{{ownerUsername}}/{{projectName}}/{{sessionPathComponent}}/{{runId}}/#/?username=domino&password=domino"
    rewrite: false
    requireSubdomain: false
matlab:
  title: "MATLAB"
  iconUrl: "https://raw.githubusercontent.com/dominodatalab/partner-resources/main/assets/workspaces/Mathworks/MATLAB/matlab.png"
  start: [ "/opt/domino/workspaces/matlab-webdesktop/start" ]
  httpProxy:
    port: 8888
    internalPath: "/{{ownerUsername}}/{{projectName}}/{{sessionPathComponent}}/{{runId}}/matlab/index.html"
    rewrite: false
    requireSubdomain: false
```

Because it is built on top of `quay.io/domino/base:Ubuntu18_DAD_Py3.6_R3.6_20190916`, you can add any of the following sections for Workspaces from that Environment:

```yaml theme={null}
jupyter:
  title: "Jupyter (Python, R, Julia)"
  iconUrl: "/assets/images/workspace-logos/Jupyter.svg"
  start: [ "/opt/domino/workspaces/jupyter/start" ]
  supportedFileExtensions: [ ".ipynb" ]
  httpProxy:
    port: 8888
    rewrite: false
    internalPath: "/{{ownerUsername}}/{{projectName}}/{{sessionPathComponent}}/{{runId}}/{{#if pathToOpen}}tree/{{pathToOpen}}{{/if}}"
    requireSubdomain: false
jupyterlab:
  title: "JupyterLab"
  iconUrl: "/assets/images/workspace-logos/jupyterlab.svg"
  start: [  "/opt/domino/workspaces/jupyterlab/start" ]
  httpProxy:
    internalPath: "/{{ownerUsername}}/{{projectName}}/{{sessionPathComponent}}/{{runId}}/{{#if pathToOpen}}tree/{{pathToOpen}}{{/if}}"
    port: 8888
    rewrite: false
    requireSubdomain: false
vscode:
  title: "vscode"
  iconUrl: "/assets/images/workspace-logos/vscode.svg"
  start: [ "/opt/domino/workspaces/vscode/start" ]
  httpProxy:
    port: 8888
    requireSubdomain: false
rstudio:
  title: "RStudio"
  iconUrl: "/assets/images/workspace-logos/Rstudio.svg"
  start: [ "/opt/domino/workspaces/rstudio/start" ]
  httpProxy:
    port: 8888
    requireSubdomain: false
```

### (Optional) Persist MATLAB preferences and add-ons between sessions

To persist your MATLAB Preferences and Add-ons between Domino sessions, you can define a **Post Run Script** to automatically copy them to your Project Files when you **Stop** and **Sync** a session, and define a **Pre Run Script** to copy them from your Project Files into the locations MATLAB will recognize at the start of subsequent sessions.

Put the following lines into your **Pre Run Script**.

```bash theme={null}
if [ -d /mnt/matlab-addons ]; then
    mkdir -p /home/ubuntu/Documents/MATLAB/SupportPackages/$MATLAB_VERSION/
    rsync -r /mnt/matlab-addons/ /home/ubuntu/Documents/MATLAB/SupportPackages/$MATLAB_VERSION
fi
if [ -d /mnt/matlab-preferences/$DOMINO_STARTING_USERNAME ]; then
    mkdir -p /home/ubuntu/.matlab/$MATLAB_VERSION/
    rsync -r /mnt/matlab-preferences/$DOMINO_STARTING_USERNAME/ /home/ubuntu/.matlab/$MATLAB_VERSION
fi
```

Put the following lines into your **Post Run Script**.

```bash theme={null}
if [ -d /home/ubuntu/Documents/MATLAB/SupportPackages/$MATLAB_VERSION ]; then
    mkdir -p /mnt/matlab-addons
    rsync -r /home/ubuntu/Documents/MATLAB/SupportPackages/$MATLAB_VERSION/ /mnt/matlab-addons
fi
if [ -d /home/ubuntu/.matlab/$MATLAB_VERSION ]; then
    mkdir -p /mnt/matlab-preferences/$DOMINO_STARTING_USERNAME
    rsync -r /home/ubuntu/.matlab/$MATLAB_VERSION/ /mnt/matlab-preferences/$DOMINO_STARTING_USERNAME
fi
```

These scripts will save add-ons **per project**, so that any collaborators launching a Workspace in the same Project will have the same add-ons. For preferences, however, they will be saved **per user** in the Project so that each user can have a different set of preferences.

## (Optional) Generate a startup script for proxy settings

If your company uses a proxy to connect to external networks, you might already have lines like the following in many of your Compute Environment Dockerfiles:

```bash theme={null}
ENV http_proxy='http://someusername:password123@proxy.company.com:80'
ENV https_proxy='http://someusername:password123@proxy.company.com:80'
ENV HTTP_PROXY='http://someusername:password123@proxy.company.com:80'
ENV HTTPS_PROXY='http://someusername:password123@proxy.company.com:80'
```

Without setting the proxy information in MATLAB as well, you may not be able to connect to external networks from MATLAB (for example, for downloading community Add-ons). Proxy information can be set manually in MATLAB under **Preferences** > **Web**, and these will be persisted across sessions if the **Pre** and **Post Run Scripts** from the previous section are included in your Environment.

Alternatively, you can define a `startup.m` file in your Project to ensure the proxy settings are correct at every launch of MATLAB. The file would look something like the following.

```matlab theme={null}
% This startup file was created from the Environment pre-run script, to set proxy settings for MATLAB
disp('Setting proxy configuration via startup.m file')
com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxy(true)
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyHost('proxy.company.com')
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPort('80')
com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxyAuthentication(true)
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyUsername('someusername')
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPassword('password123')
```

Put the following lines into your **Pre Run Script** to automatically generate such a file in any Project where it does not exist, whenever this Compute Environment is used to launch a session. (Omit the Authentication, Username, and Password lines if your proxy does not use them.)

```bash theme={null}
if [ ! -f /mnt/startup.m ]; then
    echo "% This startup file was created from the Environment pre-run script, to set proxy settings for MATLAB" > /mnt/startup.m
    echo "disp('Setting proxy configuration via startup.m file')" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxy(true)" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setProxyHost('proxy.company.com')" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPort('80')" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxyAuthentication(true)" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setProxyUsername('someusername')" >> /mnt/startup.m
    echo "com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPassword('password123')" >> /mnt/startup.m
fi
```

### Build and test the Environment

Click **Build** when you have finished editing the above sections. The Revisions page for the Environment opens.

If the new revision builds successfully, you are ready to test. Go to the Project Settings for a Project where you want to use MATLAB and change the Compute Environment to use this new Environment. After you do, you will see a MATLAB icon as an option for Workspaces in that Project.

See the [Troubleshooting](#faq-and-troubleshooting) section for information about known issues and frequently encountered problems if anything does not work as expected.

## FAQ and troubleshooting

### GPU functionality does not work

The most common problem with GPU functionality is not having the correct NVIDIA driver version for your Environment configured in your Hardware Tier. The following shell command should print some information about the GPU driver versions so you can verify it with the compatibility tables referenced in the `Prerequisites` section.

```matlab theme={null}
>> !nvidia-smi
Wed May 13 00:00:16 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64.00    Driver Version: 440.64.00    CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  Off  | 00000000:00:1B.0 Off |                    0 |
| N/A   39C    P0    50W / 300W |      0MiB / 16160MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla V100-SXM2...  Off  | 00000000:00:1C.0 Off |                    0 |
| N/A   41C    P0    50W / 300W |      0MiB / 16160MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla V100-SXM2...  Off  | 00000000:00:1D.0 Off |                    0 |
| N/A   40C    P0    52W / 300W |      0MiB / 16160MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla V100-SXM2...  Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   40C    P0    54W / 300W |      0MiB / 16160MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+
```

### MATLAB Workspace fails to launch

#### License configuration problems

License issues are the most common cause of problems launching a MATLAB Workspace. To debug, start a Jupyter or RStudio Workspace (still using the MATLAB Environment) and open a terminal. Check if your license server information has been correctly entered into the `network.lic` file, in the correct part of the MATLAB directory structure (i.e. matching your MATLAB version):

```bash theme={null}
$ which matlab
/usr/local/MATLAB/R2019b/bin/matlab
$ cat /usr/local/MATLAB/R2019b/licenses/network.lic
```

If that contains the license server information you expect, but there are still problems, you can use the `lmutil` utility to check that the license server is reachable and contains the correct information.

```bash theme={null}
$ lmutil lmstat -a -c 27000@lic1.customer.com
```

It should output information on the licenses being managed by that license server, including the MATLAB licenses.

### Advanced troubleshooting

The Workspace launch process for MATLAB respects several Environment variables related to logging, which may help you debug more obscure or advanced problems. You can set these as Project-level Environment variables, similar to how you would [set Environment variables for secure credential storage](/cloud/platform-capabilities/core-concepts/compute-environments/manage-compute-environments/manage-environment-variables), to enable toggling them on or off without having to edit the Compute Environment.

* `WS_LOGGING=[MATLAB]|ALL|DEBUG`. By default, only the MATLAB logs are shown.

  * `ALL` shows logs for the underlying screen management **xterm** and **xpra**.

  * `DEBUG` shows everything from `ALL`, and activates a flag to show all commands.

* `TTY_MODE=[disabled]|PRE|POST`. Runs **ttyd** before or after the Workspace. It’s a terminal that runs in a browser so you can easily inspect things.

  * `PRE` will run **ttyd** before the Workspace launch.

  * `POST` will run **ttyd** after the Workspace launch fails (if it fails).

* `START_LOGGING=[false]|true`. Increases logging verbosity in certain stages.

### MATLAB Workspace is laggy

In poor network conditions you may notice some lag in typing and general interactions with the MATLAB UI. This is to be expected in certain circumstances. Other common Domino Workspaces like Jupyter or RStudio use browser-based IDEs, while this MATLAB Environment is running a (Linux) desktop version of MATLAB in a remote desktop style interface. This results in more sensitivity to slow network conditions than a browser-based IDE.

For these situations, if you encounter them frequently, you may find it useful to install the [Domino CLI](/cloud/reference/cli/install-the-cli) on your local machine to facilitate editing files locally, then syncing them to Domino.

### Keyboard shortcuts for copy/paste do not work

MATLAB in Domino runs the Linux version of MATLAB, which uses the "Emacs" set of keyboard shortcuts by default. To enable keyboard shortcuts `Ctrl+C` and `Ctrl+V` for copy and paste, go to **Preferences** > **Keyboard** > **Shortcuts** and change this from **Emacs** to **Windows**. See the [MATLAB help](https://www.mathworks.com/matlabcentral/answers/103161-why-am-i-unable-to-use-copy-ctrl-c-and-paste-ctrl-v-keyboard-short-cuts-in-the-text-editing-mode) for more details.

### Connection error when downloading Add-ons or using urlread

If you get network errors when downloading Add-ons or using `urlread` to download files, it may be due to proxy settings. See the `Proxy` section above for options for setting your proxy in MATLAB either within the current session or more globally.

### Toolbox is not available

A selection of Toolboxes is pre-installed in each MATLAB base image, but this might not include every Toolbox you have on your local installation. You can see the list of Toolboxes by running the `ver` command within MATLAB, and the list is also documented for each [base image](#choose-a-base-image). You can contact your Domino account team with any specific requests for Toolboxes to include.

In addition to having the Toolbox installed in the base image, you must have an available license for using it on your [license server](#prerequisites).

## Known issues and release notes

If your problem is not listed in this FAQ, it may be worth checking the release notes for the [base image](#choose-a-base-image) you are using. Especially if your Environment is built on an older image tag, checking the release notes of newer images may give you a quick answer about whether rebuilding on the most current image will help.

*MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See [https://www.mathworks.com/company/trust-center/trademarks.html](https://www.mathworks.com/company/trust-center/trademarks.html) for a list of additional trademarks.*
