Creating MATLAB data structures in C# library to use in MATLAB

15 ビュー (過去 30 日間)
Constantin
Constantin 2021 年 10 月 14 日
コメント済み: Constantin 2021 年 10 月 20 日
I am trying to interface a C# library to MATLAB. Using standard properties and methods works fine, however the performance is slow. I figured I'd try to use MWArray.dll to create MATLAB data structures directly in C# with an interface DLL which will be called by MATLAB.
However, whenever I call a method that uses MWArray, I get a type initializer error:
The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.
My C# class looks like this:
using MathWorks.MATLAB.NET.Arrays;
namespace Dummy.MatlabInterop
{
public class Example
{
public MWStructArray getStruct()
{
return new MWStructArray(new int[] { 1, 1 }, new string[] { "Dummy" });
}
}
}
This is called by MATLAB like this:
NET.addAssembly(fullfile(pwd, 'Dummy.MatlabInterop.dll'));
ex = Dummy.MatlabInterop.Example();
s = ex.getStruct(); % <- This throws 'The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWArray' threw an exception.'
The dll is created for 64bit. I cannot find much documentation on this. Is this approach valid? What am I doing wrong? Any advice would be much appreciated.

採用された回答

Kojiro Saito
Kojiro Saito 2021 年 10 月 20 日
MathWorks.MATLAB.NET.Arrays is a part of MATLAB Compiler SDK and is different from MATLAB's external interface for .NET.
As NET.addAssembly document says, "NET.addAssembly does not support assemblies generated by the MATLAB Compiler SDK™ product.", so we cannot call the .NET libraries which use MathWorks.MATLAB.NET.Arrays.
  1 件のコメント
Constantin
Constantin 2021 年 10 月 20 日
Thank you for the reply. I will use a different approach.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on MATLAB Compiler SDK in Help Center and File Exchange

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by