Embed a function from a Matlab MEX file directly in Python
Question: I am using a proprietary Matlab MEX file to import some simulation results in
Matlab (no source code available of course!). The interface with Matlab is
actually really simple, as there is a single function, returning a Matlab
struct. I would like to know if there is any way to call this function in the
MEX file directly from Python, without having to use Matlab?

What I have in mind is for example using something like SWIG to import the C
function into Python by providing a custom Matlab-wrapper around it... By the
way, I know that with scipy.io.loadmat it is already possible to read Matlab
binary *.mat data files, but I don't know if the data representation in a mat
file is the same as the internal representation in Matlab (in which case it
might be useful for the MEX wrapper).

The idea would be of course to be able to use the function provided in the MEX
with no Matlab installation present on the system.

Thanks.


Answer: Unless I'm misunderstanding something about how Matlab works or about your
question, it is very highly unlikely to be possible. From a technical point of
view any solution would need to be a full, binary compatible, bug for bug,
feature for feature reimplementation of the Matlab C library, (implementing
mxGetPr, mxGetN and so on) but binding to Python.

Let me edit my own answer to say the following: If you do have a MATLAB
license available there is the excellent package [MLAB
wrap](http://mlabwrap.sourceforge.net) which does at least part of what you
want.

