Matlab和C#混合编程之数组传值

在Matlab与C#混合编程中,如何实现数组传递是一个重要的问题,下面介绍一下数组传值方法

首先要引用MWArray.dll(添加引用--〉浏览--〉C:\Program Files\MATLAB\R2012b\toolbox\dotnetbuilder\bin\win32\v2.0\mwarray.dll)

之后使用其中的MWNumericArray类进行强制类型转换,示例如下:

           double[] x = new double[5];
            double[] y = new double[5];
            for (int i = 0; i < 5; i++)
            {
                x[i] = i;
            }
            y[0] = y[4] = 2; y[1] = y[3] = 1; y[2] = 3;

            matlabfunction.matlabfunction mat = new matlabfunction.matlabfunction();
           
            MWNumericArray a = new MWNumericArray(1, 5, x);//int row,int column,double[] real
            MWNumericArray b = new MWNumericArray(1, 5, y);
            MWArray res = mat.calculateAllDistance(a,b);
            Console.WriteLine("distanceall=" + res);

你可能感兴趣的:(C#,matlab,编程)