MATLAB kernel for Jupyter
To run MATLAB code within Jupyter notebooks, set up the MATLAB kernel in your environment.
Prerequisites
Ensure you have MATLAB R2025b installed (required for Python 3.12+ compatibility).
Your conda environment should be using Python 3.12.
Installation steps
Activate your environment:
conda activate neurowaves-lab-documentation
Install Jupyter and the MATLAB kernel:
conda install notebook jupyter_client pip install matlab_kernel
Install the MATLAB Engine for Python. Navigate to your MATLAB installation folder (for example
C:\Program Files\MATLAB\R2025b\extern\engines\python) and install the engine:cd "C:\Program Files\MATLAB\R2025b\extern\engines\python" python -m pip install .
Using the kernels
Two kernels are available in Jupyter:
Matlab: starts a new, independent MATLAB session for the notebook.
Matlab (Connection): connects to an already running MATLAB instance, allowing you to share the workspace.
To use the Connection kernel:
In your standalone MATLAB command window, run:
matlab.engine.shareEngineIn Jupyter, select the Matlab (Connection) kernel. You can now access variables from your standalone MATLAB session using commands like
whoor simply by typing the variable name.