How can I convert matrix of type MWArray (returned from matlab runtime) to a 2-dim array (double[,]) in C#?
I am working on the simplest matlab & .NET integration as explained in: http://domoreinlesstime.wordpress.com/2013/01/26/access-matlab-from-c/
With the following statement I can convert the variable result of type MWArray to a 1-dim array:
double[] arr = (double[])((MWNumericArray)result).ToVector(MWArrayComponent.Real);
Is there a simple way to convert result into a 2-dim array in C#?
You create a double-precision array automatically when you assign a numeric scalar or array to a variable, such as A = [1 2 3; 4 5 6] . The variable A has type double .
Conversion of a Matrix into a Row Vector. This conversion can be done using reshape() function along with the Transpose operation. This reshape() function is used to reshape the specified matrix using the given size vector.
Each element of the 2nd row is a cell array. And each of those cell arrays has two elements (1x2 dimension). Each of those two elements is in and of itself a MATLAB double variable.
The following should be enough (worked for me):
double[,] arr = (double[,])((MWNumericArray)result).ToArray(MWArrayComponent.Real);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With