C# matlab混合开发----------调用matlab封装的Dll及数组类型转换

使用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 } };

具体需要什么类型 需要自行转换调用!

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值