Convert .net System.Int32[] to matlab matrix

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?

Answers


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[]              

MATLAB Builder NE add-on will hopefully solve your problem. Try it.


Need Your Help

Can CMake/CPack generate multiple NSIS installers for a single project?

windows cmake cpack

I have a single project (with sub-projects) for which I would like to generate multiple NSIS installer executables, instead of having multiple components listed in a single NSIS installer. Is this

Unable to connect to Salesforce using RestAPI: INVALID SESSION

android rest salesforce

Hi i am trying to connect to Salesforce with the Rest API and i want to retrieve sObjects..Implementing as below