python and matlab

Sturla Molden sturla.molden at gmail.com
Fri Feb 7 00:28:26 EST 2014


Sam Adams <cuongpn at gmail.com> wrote:

> Thanks Sturla, could you please explain in more details, I am new to Python :)

All the information you need to extend or embed Python is in the docs. 

Apart from that, why do you need Matlab? A distro like Enthought Canopy or
Anaconda has all the tools you will ever need for scientific programming.
Embedding Python is almost never the right solution to a problem. But if
you really need Matlab, you will be far better off by calling Matlab engine
from Python (e.g. using ctypes or Cython). 

There are also packages like mlab and matlabwrap that will help you embed
Matlab in Python:

   https://pypi.python.org/pypi/mlab
   http://mlabwrap.sourceforge.net

Apart from that, you can also invoke Python from Matlab like this:

   arg1 = 'script.py';
   s = system(sprintf('python %s', arg1));

or 

   arg1 = 'some Python code';
   s = system(sprintf('python -c "%s"', arg1));

Or if you are on Windows, you can use pywin32 to create an ActiveX server
with Python, and invoke that from Matlab.


Sturla




More information about the Python-list mailing list