python and matlab

S

Sturla Molden

Sam Adams said:
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
 
R

Rustom Mody

Sam Adams wrote:
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).

Dont know the software involved so only some general comments

When you connect two disparate pieces of significant software there is
inherently an impedance mismatch.

What Sturla is probably saying is that the matmab-python imp-mismatch is
so high that jumping across is almost certainly not worth the trouble.

And BTW have you seen sage?
http://www.sagemath.org/
 
S

Sturla Molden

Rustom Mody said:
What Sturla is probably saying is that the matmab-python imp-mismatch is
so high that jumping across is almost certainly not worth the trouble.

I am saying that the abundance of Python packages for numerical and
scientific computing (NumPy et al.) and their quality is now so good that
binding Python to Matlab is not worth the effort. The only reason to do
this would be if Matlab is needed for a very special reason. E.g. there
might be a toolbox only available for Matlab, or there might be an
administrative decision to use Matlab albeit a Python package is needed.
But if it is just a general feeling that Python lacks the tools needed for
numerical computing, then it is a false assumption and not worth it.

Note that hardly any of the tools used for numerical computing with Python
is in the standard library. They are all focused around NumPy as the
central package. See scipy.org for further information.
And BTW have you seen sage?
http://www.sagemath.org/

Sage is supposed to be a computer algebra system, i.e. a free alternative
to Maple or Mathematica.

Matlab is not a CAS system but a scripting environment for numerical
computing. Enthought Canopy and Anaconda are similar environments based on
Python.

enthought.com
continuum.io

While they require a payed license, it is also possible to hand-pick the
needed packages and install them ourselves. But for libraries like NumPy to
be liked against high-performance libraries like Intel MKL, we must build
them ourselves or use one of the commercial Python distros for scientific
computing.

Sturla
 
P

pavlovevidence

is it able to utilize functions written in Python in Matlab?

If it's on Windows, and if it's pure-Python 2.x code, the easiest solution would be to use Iron Python or Jython. Matlab can call Java and .NET code natively.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top