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 the list, starting with index 2. Then call ToArray to create a System.String array dArr, and display the results:

temp = GetRange(dc,2,3);
dArr = ToArray(temp);
for i = 1:dArr.Length
  disp(dArr(i))
end
Spinosaurus
Velociraptor
Triceratops

To create a MATLAB® array D:

D = {char(dArr(1)),char(dArr(2)),char(dArr(3))}
D = 
    'Spinosaurus'    'Velociraptor'    'Triceratops'

Now you can use D in MATLAB functions. For example, if you type:

D'
ans = 
    'Spinosaurus'
    'Velociraptor'
    'Triceratops'

Sort the array alphabetically:

sort(D)
ans = 
    'Spinosaurus'    'Triceratops'    'Velociraptor'
Was this topic helpful?