Using MATLAB w/ Jupyter
Starting Fall 2018, Jupyter Notebook will be heavily used for instruction in course BMEB4020: Computational Neuroscience, Circuits in the Brain.
Jupyter Notebook is a fantastic tool for documenting and sharing ideas and code. It provides a HTML interface (front end) for a variety of backend kernels (e.g. Python, R, Julia, MATLAB, etc.) You can find a list of interesting notebooks on Project Jupyter’s homepage here
Because Jupyter Notebook allows us to write text & LaTex (in Markdown syntax) and Code as well as render code results in a single document, it is well suited for instructional purposes. Over the past year, we have created a list of notebooks to augment the E4020 Learning experience and we will hand them out as we progress through the course.
Notebook Example obtained here.
Though not required, you’re encouraged to use Jupyter Notebook to submit homeworks for the course. Here we briefly go through the setup for using Jupyter Notebook with both Python and MATLAB.
Jupyter + MATLAB
For this setup, you will need a local MATLAB installation. All Columbia SEAS graduate students should have a license for free.
To setup Jupyter w/ MATLAB, you will need to do the following:
- Obtaining a local python. I encourage you to use a Python Package manager like Anaconda or Miniconda to install and manage Python. Download the Anaconda/Miniconda consistent with your computer’s operating system and your preferred base python version.
- Once you have a local MATLAB and python installation, install
Python
support for MATLAB as shown here. This requires no additional software other than your existing MATLAB. - Install Jupyter Notebook. The Jupyter Notebook package cannot be installed via
.exe
or.pkg
installers like MATLAB, instead it is hosted on PyPI as aPython
package. I again encourage you to use Anaconda to installJupyter Notebook
. See next section for more details. - Install
matlab_kernel
withpip
(see next section with more details) that connects your MATLAB’s Python support instep 1
with the Jupyter Notebook instep 2
.
This setup works for Linux and MacOS. For windows setup of Anaconda, see this tutorial.
Anaconda environment setup for MacOS/Linux
You are strongly encouraged to use Anaconda as a python package manager and it has many important advantages, one of which is Conda Environments. Conda environments allow you to have isolated software environment which are designed to avoid global namespace pollution and enhancing code reproducibility.
After installing Anaconda, open terminal and type in the following:
conda create -n matlab python=3.6 // create conda environment called matlab with python3.6
conda activate matlab // activate the environment called matlab
pip install jupyter matlab_kernel // install both jupyter and matlab_kernel
When all is said and down, you can launch Jupyter Notebook by typing
jupyter notebook
in your command line.
Troubleshooting
Cannot install python support for matlab
This is likely due to one of the following:
- Your Python version is too new for your matlab version
- Your Python is not in your
path
.