Install Jupyter-MATLAB¶
Prerequisites
- We assume that you are comfortable with Linux command line. If not, checkout out Ryans’ tutorial for example.
- We also assume that you already have MATLAB installed and working. This tutorial is tested successfully with MATLAB R2017a on Mac/Linux/Windows.
Install the standard Jupyter-Python notebook¶
Jupyter relies on Python, so the first thing is to install Anaconda, a popular distribution of scientific Python. Experienced users prefer Miniconda to only install necessary packages, but the standard Anaconda is more convenient for beginners, especially on Windows.
Once you have conda installed, you should test the standard IPython notebook. For example, in the notebook execute
In [1]:
%%python
# I am in a MATLAB kernel so need to add the above IPython magic to use the python kernel instead.
# You can skip this magic in a standard python kernel
print('hello from Python')
hello from Python
On Mac/Linux¶
(1) Python-side configuration¶
Open the terminal, execute the following command to check your installation of anaconda and python:
which conda pip python
All of them should be inside anaconda’s directory “…/anaconda3/bin”
MATLAB R2017a only interfaces with Python3.5, so we need to create a new virtual environment:
conda create -vv -n jmatlab python=3.5 jupyter
Enter this Python environment. Stay in this environment when executing any terminal commands (pip, python, jupyter) for rest of this tutorial.
source activate jmatlab
Then, install the Matlab kernel for Jupyter.
pip install matlab_kernal
python -m matlab_kernel install
Check if the kernel is installed correctly
jupyter kernelspec list
You should see both Python and MATLAB.
(2) MATLAB-side configuration¶
Now we need to expose the MATLAB executable to Jupyter.
Find your MATLAB directory. On Mac it will be like “/Applications/MATLAB_R2017a.app”.
Go to the “extern/engines/python” subdirectory and install the Python engine.
cd “/Applications/MATLAB_R2017a.app/extern/engines/python”
python setup.py install
(3) Start Jupyter notebook¶
cd your_working_directory
jupyter notebook
Now you should see both Python and MATLAB options when launching a new notebook. Check if the MATLAB kernel is working by:
In [2]:
disp('hello from MATLAB')
hello from MATLAB
See Use MATLAB in Jupyter Notebooks for more usages.
On Windows¶
Windows is always tricker when it comes to configuring software, but all you need is basically translating Linux commands into Windows commands.
Commonly used Linux/Mac <-> Windows command mappings are:
cd folder/subfolder
<->cd folder\subfolder
(typee:
to change the disk E)pwd
<->cd
ls
<->dir
You might also need to set environment variables if commands like “python” and “conda” cannot be recognized. Add the following directories to the PATH variable:
path_to_Anaconda_dir\
path_to_Anaconda_dir\Scripts\
All steps are exactly the same as in the Mac/Linux section. Windows is indeed a litte bit annoying, but it doesn’t prevent Jupyter+MATLAB from working. Please contact me if you have any troubles.