使用matlab 2018 和vs2019 -2015 需要dll
MWArray.dll 下载地址:
https://download.csdn.net/download/qq_36074218/19777184
https://mp.csdn.net/mp_download/manage/download/UpDetailed
下面是我自己做的一个DEMO测试
matlab带啊 返回 数组 输格式 (int,int);
function [result,result1] = Test1(i,j)
result = i*j;
result1 = i+j;
end
C#代码 t
// 实例化
Test1.Class1 t = new Test1.Class1();
//调用方法, t.Trst1("返回的数据数量",“参数1“,”参数2”)
MWArray[] eng_output_array= t.Test1(2,5,3);
MWNumericArray x1 = (MWNumericArray)eng_output_array[0];
MWNumericArray x2 = (MWNumericArray)eng_output_array[1];
double[,] location1 = (double[,])x1.ToArray(MWArrayComponent.Real);
double[,] location2 = (double[,])x2.ToArray(MWArrayComponent.Real);
var str=location1[0, 0].ToString();
var str1 = location2[0, 0].ToString();
有些传输参数需要传的类型不同 比如这个
/// <summary>
/// 数组转二维数组
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public double[,] chuliData(double[] obj)
{
double[,] dat = new double[400, 1];
for (int i = 0; i < 400; i++)
{
dat[i / 1, i % 1] = obj[i];
}
return dat;
}
类名字.Class1 gc = new 类名字.Class1();
MWNumericArray h1 = new MWNumericArray(chuliData("一维数组1"));
MWNumericArray h2 = new MWNumericArray(chuliData("一维数组2));
var ccc = new 类名字.Class1().方法(2, h1, h2);
MWNumericArray x1 = (MWNumericArray)ccc[0];
MWNumericArray x2 = (MWNumericArray)ccc[1];
double[,] location1 = (double[,])x1.ToArray(MWArrayComponent.Real);
double[,] location2 = (double[,])x2.ToArray(MWArrayComponent.Real);
this.label1.Text = location1[0, 0].ToString();
this.label2.Text = location2[0, 0].ToString();
double[] d1=new double[]{1,2,3,4,5,6,7,8,9}
//转换后的2维数组
double[,] d1 = new double[9, 1] { { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 } };
具体需要什么类型 需要自行转换调用!