The command line is a large part of any Matlab user’s workflow. This vital tool, however, isn’t as user friendly as it should be: it’s cumbersome to recall multi-line commands from the history, there’s no support for Vim key bindings, and there’s no syntax highlighting if using the
nodesktop option (on a remote computer, say). Fortunately, there’s an alternative that avoids these problems: IMatlab.
Do I need an alternative?
Using Matlab with the approach laid out below may or may not suit your workflow. Keep reading if you want (i) a customisable, attractive command line, (ii) Vim key bindings, or (iii) a minimalist Matlab workflow.
Note also that imatlab requires Matlab R2016 or later. (matlab_kernel provides a similar functionality for older versions.)
What is IMatlab?
I’ve been spoilt in the last few years by the Jupyter console (aka the IPython console). This particularly user-friendly tool lead me on a search to find something comparable for Matlab. As it turns out, Matlab can be run as a Jupyter kernel. (You don’t need to know what a ‘Jupyter kernel’ is, by the way).
An IMatlab session is started with the command
jupyter console --kernel imatlab
For me, that session might look something like this
As well as being a command line tool, IMatlab can act as the kernel for a Jupyter Notebook. Let’s redo the session above, but now in a browser, where the code can be combined with documentation:
Using Matlab without opening Matlab
Although IMatlab is a great command line tool, it leads to the obvious question: how do I do everything else I usually do in Matlab?
- To edit m-files, find a better editor
- To open the help browser, type
- To open a variable in the variable editor, say
- To show the workspace window, type
Installing and customising IMatlab
Installing IMatlab isn’t too difficult, but there are a few steps. The links below go to a download or a page with the appropriate installation commands.
- Download and install the Anaconda distribution
Although its a large download at 300–500MB, the Anaconda distribution greatly simplifies the installation of anything Python related. Be sure to download the Python 3, not 2, version.
- Install the Matlab Engine API for Python
The instructions on this page include the command
python setup.py install
Ensure that the
pythonbinary being called is the one associated with the Anaconda distribution, not another installation of python somewhere else on the computer.
- Install IMatlab itself
The following worked for me
pip install imatlab --user
python -mimatlab install --user
See the IMatlab page for other installation options
Generate a configuration file with the command
jupyter console --generate-config
This will create a file
~/.jupyter(Linux and Mac) or
The newly generated file is full of customisation suggestions, such as choosing Vim bindings over the default Emacs binding.