Any idea how to open Matlab and run M-files by using Python?

sturlamolden sturlamolden at yahoo.no
Mon Dec 3 21:12:59 EST 2007


On 3 Des, 05:02, itcecsa <itce... at gmail.com> wrote:

> I am implementing a small Python project, what I am going to do is to
> open Matlab and run some M-files, and get some output from Matlab
> command prompt.
>
> I have no idea how to open Matlab from Python!

Do you really want to do that? NumPy, SciPy, Matplotlib, f2py, etc.
are probably a better option. You don't need to rely on Matlab to do
serious numerical and scientific computing in Python. Remember that
NASA uses Python to process image data from the Hubble telescope.

Anyhow... If you really need to do this, there are several ways to
proceed:

* Call the "Matlab engine" using ctypes. There is only nine C
functions you need to wrap, and it should be straight forward. (This
is what I would try first.)

* Use Pyrex or SWIG to generate a wrapper to the Matlab engine C
frontend instead of using ctypes.

* Wrap the six functions in the Matlab engine's Fortran frontend with
f2py.

* Use pywin32 and COM to start Matlab as an ActiveX server
("Matlab.Application").

* Spawn a Matlab process using the subprocess submodule. Communicate
with your Matlab script's standard input and output streams (file id 1
in Matlab).

* See if you can get the old PyMat wrapper for the Matlab engine to
build and work.




More information about the Python-list mailing list