Calling a MATLAB function from C#

∥☆過路亽.° 提交于 2019-11-27 19:31:29
Lukas Kabrt

There is nice example in the MATLAB Central.

It shows three ways on how to communicate with MATLAB:

  1. COM
  2. MATLAB .NET Bulider
  3. MATLAB compiler

COM (I do not have any experience with it)

Cons: MATLAB is required to be installed on the target computer.

MATLAB .NET builder compiles your MATLAB code to the .NET assembly and you can use it directly.

Pros: MATLAB is not required to be installed on the target computer

Cons: It's expensive

MATLAB compiler compiles your MATLAB code into a C/C++ library or EXE file. You can use it through P/Invoke.

Pros: MATLAB is not required to be installed on the target computer

Cons: It's expensive, a lot of P/Invoke.

user287107

There is a third option: delegates. Starting MATLAB -> load .NET assembly -> execute .NET function with delegate handle to a MATLAB function.

There is a great example on this site on setting up everything. You can use MATLAB .NET deployment tool.

You need to

  • Install MCR (Matlab Compiler Runtime).
  • Deploy your Matlab function to .NET Assembly using Matlab Deploy Tool. This will create a .dll file.
  • Add .dll reference inside your .NET project.
  • Add reference to MATLAB.NET.

The advantage of this method is that the target machine does not require MATLAB to be installed, but on the downside the execution is quite expensive.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!