176

I have a bunch of MATLAB code from my MS thesis which I now want to convert to Python (using numpy/scipy and matplotlib) and distribute as open-source. I know the similarity between MATLAB and Python scientific libraries, and converting them manually will be not more than a fortnight (provided that I work towards it every day for some time). I was wondering if there was already any tool available which can do the conversion.

4
  • 9
    another possibility is to release your source code as is, and test it in Octave (www.gnu.org/software/octave) which has 99% matlab competability. Commented Mar 26, 2012 at 5:22
  • 6
    @josliber: Can we move this question to softwarerecs.stackexchange.com so that it can be reopened? Commented Aug 7, 2016 at 19:54
  • @andersongreen the question is too old for migration Commented Aug 7, 2016 at 20:20
  • 2
    I think now the best way to do this is to use matlab built-in tool mcc Commented Nov 14, 2018 at 13:45

2 Answers 2

186

There are several tools for converting Matlab to Python code.

The only one that's seen recent activity (last commit from June 2018) is Small Matlab to Python compiler (also developed here: SMOP@chiselapp).

Other options include:

  • LiberMate: translate from Matlab to Python and SciPy (Requires Python 2, last update 4 years ago).
  • OMPC: Matlab to Python (a bit outdated).
  • Mat2py: Matlab to Python (Requires Python 2).

Also, for those interested in an interface between the two languages and not conversion:

  • pymatlab: communicate from Python by sending data to the MATLAB workspace, operating on them with scripts and pulling back the resulting data.
  • Python-Matlab wormholes: both directions of interaction supported.
  • Python-Matlab bridge: use Matlab from within Python, offers matlab_magic for iPython, to execute normal matlab code from within ipython.
  • PyMat: Control Matlab session from Python.
  • pymat2: continuation of the seemingly abandoned PyMat.
  • mlabwrap, mlabwrap-purepy: make Matlab look like Python library (based on PyMat).
  • oct2py (repository): run GNU Octave commands from within Python.
  • pymex: Embeds the Python Interpreter in Matlab, also on File Exchange.
  • matpy: Access MATLAB in various ways: create variables, access .mat files, direct interface to MATLAB engine (requires MATLAB be installed).
  • MatPy: Python package for numerical linear algebra and plotting with a MatLab-like interface.

Btw might be helpful to look here for other migration tips:

On a different note, for people who might find it useful there is:

Sign up to request clarification or add additional context in comments.

4 Comments

Does anyone have a comment on which of these works best or which cases fail?
I haven't tested them yet either, but it seems like smop has the sole distinction of being actively maintained, by the original developer, on github, with a test suite.
which one is the fastest to call matlab functions out of the methods establishing an interface?
there is github.com/mat2py/mat2py which is new and distinct from the mat2py mentioned above. You can see the output of its translations at translate.mat2py.org and test it in console.mat2py.org
8

There's also oct2py which can call .m files within python

https://pypi.python.org/pypi/oct2py

It requires GNU Octave, which is highly compatible with MATLAB.

https://www.gnu.org/software/octave/

1 Comment

Although this may look like a link-only NAA, it is actually an appropriate answer to the question. That the question is inappropriate (off-topic) is a separate issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.