Reputation: 79
I have developed C# dll as assembly that has a method which returns a generic list - List<T>
.
I am calling this method from Matlab and get the returned values as System.Int32[]
.
How do I convert this Type to Matlab matrix (or cells) in order to use it more freely inside Matlab?
Even better, can I make the dll to auto return 'Matlab style' array if it being called by Matlab?
Upvotes: 4
Views: 1974
Reputation: 124563
Suppose we had the following array of type System.Int32[]
(as 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 be more specific:
M = int32(arr)
The result:
>> whos
Name Size Bytes Class Attributes
M 1x5 20 int32
arr 1x1 60 System.Int32[]
Upvotes: 6