Matlab 和 C# 之间的互操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/434331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Interoperating between Matlab and C#
提问by smaclell
After peeking around the internet it looks like it is possible to interop between C# and Matlab. I am wondering if anyone has had success with it and what they did to do so. If possible somehow pulling it off without the use of COM. Thanks for your time.
在浏览互联网之后,看起来可以在 C# 和 Matlab 之间进行互操作。我想知道是否有人成功地做到了这一点,以及他们是怎么做到的。如果可能的话,在不使用 COM 的情况下以某种方式将其拉下来。谢谢你的时间。
采纳答案by Jesse Pepper
Yes, quite possible. Though I ended up using the C interface and calling into that using a mixed-mode DLL (and getting C# to call into that... but that was because I was also interfacing with some other C code). It's quite straightforward. On computers where you want to run your program, you'll need to install Matlab Runtime MCRInstaller.exe.
是的,很有可能。尽管我最终使用了 C 接口并使用混合模式 DLL 调用了它(并让 C# 调用了它......但那是因为我还与其他一些 C 代码交互)。这很简单。在要运行程序的计算机上,您需要安装 Matlab Runtime MCRInstaller.exe。
edit: removed broken link
编辑:删除断开的链接
回答by Jared
If you're willing to spend money this may be what you need:
如果你愿意花钱,这可能是你需要的:
http://www.mathworks.com/products/netbuilder/
http://www.mathworks.com/products/netbuilder/
It can generate wrappers for Matlab code that allow it to be called from both .NET and COM.
它可以为 Matlab 代码生成包装器,允许从 .NET 和 COM 调用它。
回答by Todd
Beginning with the R2009a release of MATLAB, .NET objects can be accessed from MATLAB:
从 MATLAB 的 R2009a 版本开始,可以从 MATLAB 访问 .NET 对象:
http://www.mathworks.com/help/techdoc/matlab_external/brpb5k6.html
http://www.mathworks.com/help/techdoc/matlab_external/brpb5k6.html
In older versions of MATLAB, it is possible to access .NET objects from MATLAB using CCW:
在旧版本的 MATLAB 中,可以使用 CCW 从 MATLAB 访问 .NET 对象:
http://www.mathworks.com/support/solutions/data/1-5U8HND.html?solution=1-5U8HND
http://www.mathworks.com/support/solutions/data/1-5U8HND.html?solution=1-5U8HND
and the MATLAB engine from .NET:
和来自 .NET 的 MATLAB 引擎:
You can also use the MATLAB Builder NE to wrap m-code into .NET assemblies.
您还可以使用 MATLAB Builder NE 将 m 代码包装到 .NET 程序集中。
回答by Dani
Yes, I managed to do that and it was mostly painless.
是的,我设法做到了,而且几乎没有痛苦。
You'd have to compile your MATLAB code for .NET (as explained in pervious answers), run MCR installer, reference MWArray.dll and the complied code dll in your .NET project and off you go.
您必须为 .NET 编译 MATLAB 代码(如之前的答案中所述),运行 MCR 安装程序,在 .NET 项目中引用 MWArray.dll 和编译后的代码 dll,然后就可以了。
The only annoyance was the casting (and sometimes multiple castings!) that the interface forces on you (using explicit in the cast operators)
唯一的烦恼是界面强制你进行的转换(有时是多次转换!)(在转换操作符中使用显式)
回答by Dani
In the R2009a pre-release you can call .net assemblies from MATLAB.
在 R2009a 预发行版中,您可以从 MATLAB 调用 .net 程序集。
回答by devin
I'm not sure how much this applies to you but try looking into matlab executables or MEXBasically, it's really easy to write a program in C or FORTRAN, include a few libraries and functions, and then you can use you C or FORTRAN function in matlab
我不确定这对您有多大影响,但请尝试查看 matlab 可执行文件或MEX基本上,用 C 或 FORTRAN 编写程序真的很容易,包括一些库和函数,然后您可以使用 C 或 FORTRAN 函数在matlab中
回答by Jader Dias
There is a free and open source .NET wrapper for Matlab, and it is very simple: http://www.codeproject.com/KB/dotnet/matlabeng.aspx
Matlab 有一个免费的开源 .NET 包装器,它非常简单:http: //www.codeproject.com/KB/dotnet/matlabeng.aspx
I use this.
我用这个。