Convert .net System.Int32 [] to Matlab Matrix

I developed C # dll as an assembly that has a method that returns a general list - List<T> . I call this method from Matlab and get the return values ​​as System.Int32[] .

How do I convert a type matrix to Matlab (or cells) to use it more freely inside Matlab?

Even better, can I get the dll to automatically return the "Matlab style" array if it is called by Matlab?

+4
source share
2 answers

Suppose we had the following array of type System.Int32[] (returned by your C # function):

 arr = NET.createArray('System.Int32',5); for i=1:5 arr.Set(i-1, i); end 

Now, to convert to a MATLAB matrix, we can simply do:

 M = double(arr) 

or more specifically:

 M = int32(arr) 

Result:

 >> whos Name Size Bytes Class Attributes M 1x5 20 int32 arr 1x1 60 System.Int32[] 
+5
source

The MATLAB Builder NE extension will hopefully solve your problem. Give it a try.

0
source

All Articles