如何从mathematica调用matlab函数?
我想从mathematica 调用一个matlab 函数。如何最好地做到这一点?
我在 Wolfram 网站上找到了一篇 古老的帖子 描述了一种方法,是这样的吗还有连接两者的方法吗?
I would like to call a matlab function from mathematica. How best to do that?
I have found an ancient post on Wolfram site describing a way to do this, is this still the way to connect the two?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您至少可以在Windows下尝试
NETLink
:然后您可以调用Matlab函数:
HTH
You can try
NETLink
for this at least under Windows:And then you can invoke Matlab functions:
HTH
您可以使用mEngine。预编译的 Windows MathLink 可执行文件可与 Mathematica 8 配合使用。在 Windows 上,您可能需要添加 MATLAB到系统路径。
与 NETLink 方法相比,这种方法的优点是在 Mathematica 和 MATLAB 之间传输变量就像
mGet["x"]
或mPut["x"]
一样简单。虽然这对于 NETLink 来说也是可能的,但 mEngine 的优点是您不需要自己实现它(如果像我一样您对 COM 或 .NET 一无所知,那么这很好)You can use mEngine. The precompiled Windows MathLink executable works with Mathematica 8. On Windows you may need to add MATLAB to the system path.
The advantage of this compared to the NETLink method is that transferring variables between Mathematica and MATLAB will be as easy as
mGet["x"]
ormPut["x"]
. Although this might be possible with NETLink too, the advantage of mEngine is that you don't need to implement it yourself (which is great if like me you don't know anything about COM or .NET)我认为这通常是一个困难的问题,但可以通过针对特定情况进行一些编程来轻松解决。我将用 C# 进行演示。
我会像这样建立一系列调用。
总而言之,我可以用不到 50 行 C# 代码来解决特定问题。换句话说,没有太多的工作。可能的问题是数据转换,但如果您想来回发送数据数组,MathLink 提供了很多开箱即用的功能。同样,Mathematica 可以通过 Java 连接到 MATLAB,尽管我自己还没有这样做。
也许最简单的连接可以通过 Python 进行。 Mathematica 提供了一个可安装的 MathLink python 库,位于 Mathematica\8.0\SystemFiles\Links\NETLink,Matlab 有一个名为 PyMat 的插件库,可以下载 这里,但是这个包已经维护了很长时间并且只支持最古老的Matlabs。
或者,您可以完全放弃 Matlab,转而使用 SAGE 和/或 numpy。
I would imagine that this is a difficult problem in general, but can be easily solved with a little programming for a particular case. I'll demonstrate with C#.
I would build a string of calls, like so.
All in all I could do this in less than 50 lines of C# code, for a specific problem. Not too much work, in other words. Possible problems are data conversion, but if you want to send back and forth arrays of data, MathLink offers a lot out of the box. Similarly Mathematica can be linked to MATLAB through Java, though I haven't done that myself.
Perhaps the easiest connection could be made through Python. Mathematica offers an installable MathLink python library, located at Mathematica\8.0\SystemFiles\Links\NETLink, and Matlab has an addon library called PyMat, which can be downloaded here, but this package hasn't been maintained for a long time and supports only the most ancient of Matlabs.
Alternatively you can forgo Matlab altogether in favor of SAGE and/or numpy.
现在有一个新的包用于此 --- MATLink。这是我所知道的最完整的此类包。 (免责声明:我是 MATLink 的开发人员之一。)
MATLink 让您...
从 Mathematica 中无缝调用 MATLAB 函数
在两个系统之间传输数据
p>
支持大多数 MATLAB 数据类型,包括稀疏数组、结构体和单元格。
此处提供了更完整的说明。有关详细示例,请参阅网站。
There is now a new package for this --- MATLink. It is the most complete such package I am aware of. (Disclaimer: I'm one of the developers of MATLink.)
MATLink lets you ...
seamlessly call MATLAB functions form Mathematica
transfer data between the two systems
Most MATLAB data types are supported, including sparse arrays, structs and cells.
A more complete description is available here. For detailed examples, see the website.