install Matlab Engine in Python

Related: Call Python from Matlab

Install Matlab Engine in Python

As of Matlab R2017a, this works from Python 3.5, 3.4 and 2.7.


cd $(dirname $(realpath $(which matlab)))/../extern/engines/python

python build --build-base=$(mktemp -d) install


cd %PROGRAMFILES%/MATLAB/R2017a/extern/engines/python

python build --build-base=%TEMP% install


Python program calling Matlab Engine

import matlab.engine
eng = matlab.engine.start_matlab('-nojvm')


The -nojvm Matlab Engine option is important for not having the Matlab Engine hang forever upon startup. It should take less than 1 second for Matlab Engine to start when called from Python.

Convert matlab.double arrays to Numpy arrays

enclose the matlab.double variable in numpy.asarray()

pass floats to Matlab Engine explicitly

by including a period ‘.’ after the number. e.g. asin(1) will fail, but asin(1.) will work.

you can pass N-D arrays (e.g. matrices) using the Matlab Engine

unlike the py module when using Matlab directly.  


Leave a Comment