Convert .NET Collections toMATLABArrays
Use theToArray
method of theSystem.Collections.Generic.List
class to convert a collection to an array. For example, useGetRange
to get three values from a list. Then callToArray
to create aSystem.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); AddRange(dc,dog); temp = GetRange(dc,0,3); dArr = ToArray(temp);
Create a MATLAB®arrayDogs
:
Dogs = {char(dArr(1)),char(dArr(2)),char(dArr(3))}
Dogs = 'poodle' 'spaniel' 'Irish setter'
Now you can useDogs
in MATLAB functions. For example, sort the array alphabetically:
sort(Dogs)'
ans = 'Irish setter' 'poodle' 'spaniel'