我已将 C# dll 开发为具有返回通用列表的方法的程序集 - List<T>
. 我从 Matlab 调用此方法并将返回值作为System.Int32[]
.
如何将此类型转换为 Matlab 矩阵(或单元格)以便在 Matlab 中更自由地使用它?
更好的是,如果它被 Matlab 调用,我可以让 dll 自动返回“Matlab 样式”数组吗?
假设我们有以下类型的数组System.Int32[]
(由 C# 函数返回):
arr = NET.createArray('System.Int32',5);
for i=1:5
arr.Set(i-1, i);
end
现在要转换为 MATLAB 矩阵,我们可以简单地执行以下操作:
M = double(arr)
或更具体:
M = int32(arr)
结果:
>> whos
Name Size Bytes Class Attributes
M 1x5 20 int32
arr 1x1 60 System.Int32[]
MATLAB Builder NE 插件有望解决您的问题。试试看。