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.
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 which does at least part of what you want.
You can create stand alone shared libraries from Matlab code, e.g http://www.mathworks.com/help/toolbox/compiler/mbuild.html. These you should be able to call from python. But you need the Matlab Compiler, however, it looks like there is a trial version of it available for free.
See also this stackoverflow topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With