allow users to combine rich text, code, data and computational results in a way that’s similar to our own Live Scripts
. Jupyter, however, supports a range of languages including Python, R and even compiled languages such as C++ and Fortran. They are widely used in many areas of computational research, exploration and dissemination.
I’ve been a fan and enthusiastic user of Project Jupyter since before it was called Jupyter. So, when I first joined MathWorks and got to know everyone in product management and development, one of my first questions to everyone around here was “When are we going to support Jupyter more?”
As such, it gives me immense pleasure to be able to announce that the answer is “Right now!” As of Friday 27th of January in fact when MathWorks released an updated version of jupyter-matlab-proxy to GitHub
. It’s also available in PyPI
and so is installable via pip.
The package has been around for a while now but in the past it only supported the ability to access MATLAB in a browser from environments like JupyterHub. With the new update, you can now also run MATLAB code in Jupyter notebooks via a so-called MATLAB kernel for Jupyter
. This is the first tranche of the Jupyter-related functionality that I’ve been begging for since I joined MathWorks.
The community has provided some kernel support for MATLAB for a while (Thank you Calysto) but with this release we can say that using MATLAB in Jupyter notebooks is now supported by MathWorks.
The elephant in the room – Can’t install on Windows
The practical implication of this is that you can’t install the MATLAB Jupyter kernel on a Windows machine and have it use your local Windows version of MATLAB.
Of course, since Jupyter is a web-based system, there will be plenty of ways that Windows users will be able to experience this kernel since it can be installed on remote servers. Expect to see it appearing on HPC clusters and Science Gateways
in the near future, for example.
It’s also possible to run the whole thing, MATLAB and all, in a Docker container
and use it from Windows that way – this is how I reviewed early versions of this package in fact.
We are currently evaluating the options for supporting Windows installations in a potential future release of the integration
Installing the kernel
Since my primary machine runs Windows, I decided to fire up MATLAB on an AWS VM running Linux using MathWorks Cloud Centre
. At the time of writing, this gives me a fresh Ubuntu 20.04 install along with MATLAB R2022b. I installed Jupyter Lab with
pip install jupyterlab
and then installed the MATLAB kernel package with
pip install jupyter-matlab-proxy
Since these were run with user permissions, everything was installed into /home/ubuntu/.local/bin/ which is not on the system PATH. I added the following line to my .bashrc file and I was good to go
What you get in Jupyter Lab – MATLAB notebook kernel, a browser based version of MATLAB and a console
Assuming all goes well, this is what you should see in your web browser when you run Jupyter Lab
There are 3 things I want to show you.
The first is what we’ve all been waiting for, a MATLAB kernel for Jupyter notebook. Click on that and you’ll get a new notebook running MATLAB as a kernel. Here’s one with a few commands executed.
Next is the Open MATLAB
button. When I first saw this I thought it would just be a link to my local MATLAB executable. To my delight, however, I discovered that it launches a browser-based version of MATLAB. It’s a similar experience to MATLAB Online
but running on my hardware (or the hardware of whatever server you are connected to if you are running this remotely).
Look closely at the workspace and you’ll discover that those are the variables I created in my notebook above. That is, the web version of MATLAB and the notebook are connected to the same instance of MATLAB. I can move between the two environments in whatever way I’m most comfortable with.
Finally, we have the Console version of the MATLAB kernel. Again, this is connected to the same instance of MATLAB as the other two views
The first time I tried to run a MATLAB Command in a Jupyter notebook, the licensing dialogue popped up
I signed into the MathWorks account associated with my license, the dialogue disappeared and I could proceed as you’d expect. I only had to do this once. Even when my machine was rebooted or when I restarted Jupyter Lab, I was not bothered by licensing again.
Some features of the MATLAB kernel for Jupyter
If you have used Jupyter notebooks before, you get pretty much what you’d expect. It's Jupyter but with MATLAB code. In the below, you can see that I ran the why command a few times before I got what I wanted!
Graphics are rendered inline and are static.
Expressions returned from symbolic toolbox are rendered using LaTeX
Other objects, such as tables and dictionaries, are rendered in a similar way to how they appear in the MATLAB Command Window.
There is also tab completion. For example, I typed ‘ran’, pressed Tab and was greeted with the selection below
More kernel features will be added over time. Let us know what you are interested in by creating an issue here,
sending an email to email@example.com
or discuss in the comments section below.
Limitations and things you might not expect
I’ve already covered the big one – no Windows support at the present time but there are a few other things you might want to know if you are used to using Jupyter with other languages.
Many notebooks but only one MATLAB – If you have used Jupyter with a Python kernel, you’ll be used to the idea that every notebook gets its own Python process. For this MATLAB kernel, all notebooks you run share the same MATLAB and the same workspace.
Some MATLAB commands are currently not supported in notebooks. These include:
- Commands that request interactive user input from users. For Example: input and keyboard.
- MATLAB Debugger commands. For Example: dbstep, dbup, and dbstack.
- Commands which require another browser tab to be opened. For Example: doc and appdesigner.
- Commands that create animations. For Example: movie, vibes.
- For MATLAB R2022a and earlier, LASTERR and LASTERROR do not capture MATLAB errors from execution in notebooks.
- Locally licensed MATLABs are currently not supported. Users must either login using Online Licensing or a Network License Manager.
Tell us what you think
So, there we have it. A quick tour of some of the features and limitations of our brand-new MATLAB kernel for Jupyter. As a long-time supporter and user of the Jupyter ecosystem, I am personally thrilled to see MathWorks do this.
It’s our first step into this world and we plan on doing a lot more. Please let us know what you think in the comments section. If you encounter a technical issue or have an enhancement request, create an issue here
or send an email to firstname.lastname@example.org.