直接在Python中嵌入Matlab MEX文件中的函数 [英] Embed a function from a Matlab MEX file directly in Python

查看:680
本文介绍了直接在Python中嵌入Matlab MEX文件中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用专有的Matlab MEX文件在Matlab中导入一些仿真结果(当然没有可用的源代码!).实际上,与Matlab的接口非常简单,因为只有一个函数返回了Matlab结构.我想知道是否可以直接从Python调用MEX文件中的此函数,而不必使用Matlab?

我想到的是例如使用SWIG之类的东西通过在其周围提供一个自定义的Matlab包装器将C函数导入Python中... 顺便说一句,我知道使用scipy.io.loadmat已经可以读取Matlab二进制* .mat数据文件,但是我不知道Mat文件中的数据表示是否与Matlab中的内部表示相同. (在这种情况下,它可能对MEX包装器有用).

这个想法当然是能够在系统上没有安装Matlab的情况下使用MEX中提供的功能.

谢谢.

解决方案

您可以通过Matlab代码创建独立的共享库,例如 http://www.mathworks.com/help/toolbox/compiler/mbuild.html .这些您应该能够从python调用.但是您需要Matlab编译器,但是,它似乎有免费的试用版.

另请参见 stackoverflow主题. /p>

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.

解决方案

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.

这篇关于直接在Python中嵌入Matlab MEX文件中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆