Reputation: 53
I am trying to get my hands dirty with interoperability between Matlab's .net-Application server and F#-scripting. Currently, I got stuck with a data transfer issue. If I open a new Matlab-Instance in F#-interactive:
#I @"C:\Program Files\MATLAB\R2010a\bin\win64";;
#r @"MLApp.dll";;
let matlab=new MLApp.MLAppClass();;
And then I create a Matlab-Array:
matlab.Execute("a=[1 2 3 4 5;6 7 8 9 10]");;
The next step to transfer the Matlab-array to .net would be
let b =matlab.GetVariable("a","base");;
Here is when the problem begins. The variable 'b' will be of Type 'object', providing only the generic interface of a .net-object type. How can I get retrieve a numeric array from this variable? Is there any way to apply a downcast to 'array float'?
Edit:
Okay, there is one more thing I don't understand: After applying the downcast the array has type array2D, float[,]. But is the array displayed like this:
arr;;
val it : float [,] = [[1.0; 2.0; 3.0]
[4.0; 5.0; 6.0]]
For a rectangular array, I am used to get something like this
arr;;
= [|[|1.0; 2.0; 3.0|]
[|4.0; 5.0; 6.0|]|]
Where is the difference between these types? And why can't I apply array slicing to arr of type float[,]?
Upvotes: 2
Views: 213
Reputation: 47904
Just for completeness, you can also use downcast
. I prefer this when the type of the cast can already be inferred. If you later change the type there's one less place you would need to change it.
Upvotes: 0