This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Convert .NET Collections to MATLAB Arrays

Use the ToArray method of the System.Collections.Generic.List class to convert a collection to an array. For example, use GetRange to get three values from a list. Then call ToArray to create a System.String array.

dog = NET.createArray('System.String',3);
dog(1) = 'poodle';
dog(2) = 'spaniel';
dog(3) = 'Irish setter';
dc = NET.createGeneric('System.Collections.Generic.List',{'System.String'},3);
temp = GetRange(dc,0,3);
dArr = ToArray(temp);

Create a MATLAB® array Dogs:

Dogs = {char(dArr(1)),char(dArr(2)),char(dArr(3))}
Dogs = 
    'poodle'    'spaniel'    'Irish setter'

Now you can use Dogs in MATLAB functions. For example, sort the array alphabetically:

ans = 
    'Irish setter'

Related Topics