Calling mex Function from Python extension

20 vues (au cours des 30 derniers jours)
Jim Glidewell
Jim Glidewell le 21 Sep 2016
Commenté : Bo Li le 23 Sep 2016
I am trying to write a Python extension program to call a MATLAB mex function. What I want to do is to have my program directly call the function mexFunction(...) with my own mxArray parameters, etc.
When I run the program in Python I get a DLL load error. After some experimenting I found that if I comment out the include statement for mex.h the program loads fine, but as soon as I include mex.h I get the DLL load error again.
My theory is that there is a DLL conflict because the program as been declared to be both a Python DLL and a MATLAB DLL and the system gets confused. I tried going into the mex.h file and commenting out the DLL_EXPORT command hoping I could trick it, but that didn't help. So now I'm thinking that maybe it is still getting declared as a DLL in the MATLAB lib files, but that is just a guess.
The bottom line is this. I basically want to be able to call a mex function from my own program similar to how MATLAB would call the function, passing in the mxArray variables and other parameters. I assume they are doing something like a call to LoadLibrary followed by GetProcAddress. How can I do something similar without it thinking that this is a DLL?
Thank you.

Réponses (1)

Bo Li
Bo Li le 22 Sep 2016
How do you want to invoke this MEX file? From inside MATLAB or in Python? You can use mxArray in Python without using MEX. Or you can use Python Interface to invoke the Python extension directly from MATLAB:
  2 commentaires
Jim Glidewell
Jim Glidewell le 22 Sep 2016
I need to be able to call a MATLAB mex function from within Python. I'm not sure how you would call it directly from Python because there is not way that I know of to build the required mxArrays from within Python.
Therefore, my idea was to build a Python extension DLL that would message the Python data and form it into mxArrays and call the mex function directly.
Bo Li
Bo Li le 23 Sep 2016
Maybe you can add the matlabroot/bin/win64 folder into the system PATH and see how it works.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by