In the hybrid programming of MATLAB and C #, how to implement array transfer is an important issue. Next we will introduce the array value transfer method.
First, you must reference mwarray. dll (add reference --> browse --> C: \ Program Files \ MATLAB \ r2012b \ toolbox \ dotnetbuilder \ bin \ Win32 \ V2.0 \ mwarray. dll)
Then use the mwnumericarray class to perform forced type conversion, for example:
double [] x = new double [5];
double [] Y = new double [5];
for (INT I = 0; I <5; I ++)
{< br> X [I] = I;
}< br> Y [0] = Y [4] = 2; y [1] = Y [3] = 1; y [2] = 3;
Matlab function. matlab function MAT = new Matlab function. matlab function ();
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);