Skip to content

prabhakk-mw/jupyter-matlab-proxy

 
 

Repository files navigation

MATLAB Integration for Jupyter

GitHub Workflow Status PyPI badge codecov

Run MATLAB® code in Jupyter® environments such as Jupyter notebooks, JupyterLab, and JupyterHub.

Table of Contents

  1. Features of MATLAB Integration for Jupyter
  2. Requirements
  3. Install
  4. Get Started
    1. Run MATLAB Code in a Jupyter Notebook
    2. Open MATLAB in a Browser
    3. Edit MATLAB Files in JupyterLab
  5. Limitations

Features of MATLAB Integration for Jupyter

You can use this package to run MATLAB code in Jupyter notebooks and JupyterLab.

From your Jupyter notebook or JupyterLab, you can also open the MATLAB development environment in your browser to access more MATLAB features.

Requirements

  • Supported operating systems:

  • Python versions: 3.8 | 3.9 | 3.10 | 3.11

  • MATLAB R2020b or later, installed and on the system PATH.

    # Confirm MATLAB is on the PATH
    which matlab

    Note: You only need MATLAB installed if you want to execute MATLAB code. You can open Jupyter notebooks containing MATLAB code without having MATLAB installed.

  • System dependencies required to run MATLAB:

    • The MATLAB Dependencies repository contains base-dependencies.txt files that list the libraries required to run each release of MATLAB on a given operating system. To see how to use these files, refer to the Dockerfiles in the same folder.
  • Linux based systems also require X Virtual Frame Buffer (Xvfb), which you can install with:

    # On a Debian/Ubuntu based system:
    $ sudo apt install xvfb
    
    # On a RHEL based system:
    $ yum search Xvfb
    xorg-x11-server-Xvfb.x86_64 : A X Windows System virtual framebuffer X server.
    $ sudo yum install xorg-x11-server-Xvfb

Install

Install this Python package from the Python Package Index (PyPI) or build it from the source.

Install from PyPI

python -m pip install jupyter-matlab-proxy

Installing this package will not install MATLAB. To execute MATLAB code in Jupyter, you must have MATLAB installed separately.

Build from Source

Alternatively, you can install this package by building it from the source. This requires Node.js® version 16 or higher. To install Node.js, see Node.js Downloads.

git clone https://github.com/mathworks/jupyter-matlab-proxy.git
cd jupyter-matlab-proxy
python -m pip install .

Integration with JupyterHub

To use MATLAB with JupyterHub, install the jupyter-matlab-proxy Python package in the Jupyter environment launched by your JupyterHub platform. For example, if your JupyterHub platform launches Docker containers, install this package in the Docker image used to launch those containers, using the instructions for Using MATLAB Integration for Jupyter in a Docker Container.

Using Simulink

This package lets you use Simulink® programmatically by entering commands in a Jupyter notebook. To view a model or use other Simulink features that require the Simulink UI, you can use a VNC to connect your Jupyter environment to a Linux desktop where you have MATLAB and Simulink installed. For instructions, see MATLAB Jupyter VNC Solution.

Troubleshooting

To troubleshoot package installation issues, see Troubleshooting.

Get Started

This section shows you how to:

  1. Run MATLAB Code in a Jupyter Notebook
  2. Open MATLAB in a Browser
  3. Edit MATLAB files in JupyterLab

Install Jupyter Notebook or JupyterLab:

# For Jupyter Notebook
python -m pip install notebook

# For JupyterLab 3
python -m pip install 'jupyterlab>=3.0.0,<4.0.0a0'

Note: the package allows you to execute MATLAB code in both JupyterLab 3 and JupyterLab 4, but syntax highlighting and auto indentation are currently only supported on JupyterLab 3.

⚠️ Functionality being removed or changed.
Project Jupyter ended maintenance of JupyterLab 3 on May 15, 2024. For details, see JupyterLab 3 End of Maintenance. Starting from a future release of MATLAB Integration for Jupyter, editor features such as syntax highlighting and autoindentation will be removed from JupyterLab 3 and introduced for JupyterLab 4. Execution of MATLAB code will remain available with both JupyterLab 3 and JupyterLab 4.

Open your Jupyter environment by starting Jupyter Notebook or JupyterLab.

# For Jupyter Notebook
jupyter notebook

# For JupyterLab
jupyter lab

If you are prompted for a token, click the link shown in your terminal to access your Jupyter environment.

After installing this package, you see new MATLAB options in your Jupyter environments.

Classic Notebook Interface JupyterLab

Run MATLAB Code in a Jupyter Notebook

To open a Jupyter notebook where you can run MATLAB code, click MATLAB Kernel in your notebook or JupyterLab.

Classic Notebook Interface JupyterLab

This opens a Jupyter notebook that supports MATLAB.

  • When you execute MATLAB code in a notebook for the first time, enter your MATLAB license information in the dialog box that appears. See Licensing for details. The MATLAB session can take a few minutes to start.
  • Multiple notebooks running on a Jupyter server share the underlying MATLAB process, so executing code in one notebook affects the workspace in others. If you work in several notebooks simultaneously, be aware that they share a workspace.
  • With MATLAB R2022b and later, you can define a local function at the end of the cell where you want to call it:

For technical details about how the MATLAB kernel works, see MATLAB Kernel for Jupyter.

Open MATLAB in a Browser

To access more MATLAB features, you can open the MATLAB development environment in your browser. Click the Open MATLAB button in your notebook or JupyterLab.

Classic Notebook Interface JupyterLab

Notebooks in JupyterLab also have a Open MATLAB button on the toolbar:

Clicking Open MATLAB opens the MATLAB development environment in a new browser tab.

When you use the package for the first time, enter your MATLAB license information in the dialog box that appears. See Licensing for details.

For technical details about this MATLAB development environment, see MATLAB in a Browser.

Edit MATLAB Files in JupyterLab

You can also edit MATLAB .m files in JupyterLab. Click the MATLAB File button.

This opens an untitled .m file where you can write MATLAB code with syntax highlighting and auto indentation.

  • Currently, this package allows you to edit MATLAB .m files but not to execute them.
  • To open a new MATLAB .m file, you can also use the JupyterLab command palette. Press CTRL+SHIFT+C, then type New MATLAB File and press Enter.

Limitations


Copyright 2021-2024 The MathWorks, Inc.


About

MATLAB Integration for Jupyter

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 70.8%
  • MATLAB 13.9%
  • TypeScript 13.9%
  • Shell 1.3%
  • Other 0.1%