NET.createArray
Array for nonprimitive .NET types
Description
Examples
Create .NET Array of Generic Type
Create a .NET array of List<Int32>
generic
type.
genType = NET.GenericClass('System.Collections.Generic.List','System.Int32'); arr = NET.createArray(genType,5)
arr = List<System*Int32>[] with properties: Length: 5 LongLength: 5 Rank: 1 SyncRoot: [1x1 System.Collections.Generic.List<System*Int32>[]] IsReadOnly: 0 IsFixedSize: 1 IsSynchronized: 0
Create and Initialize Jagged Array
Create a .NET array of three elements.
jaggedArray = NET.createArray('System.Double[]',3)
jaggedArray = Double[][] with properties Length: 3 LongLength: 3 Rank: 1 SyncRoot: [1x1 System.Double[][]] IsReadOnly: 0 IsFixedSize: 1 IsSynchronized: 0
Assign values to arrays of different dimensions.
jaggedArray(1) = [1,3,5,7,9]; jaggedArray(2) = [0,2,4,6]; jaggedArray(3) = [11,22];
Display the first value of the third array.
jaggedArray(3,1)
ans = 11
Create Jagged Array of Generic Type
Create a jagged array of List<Double>
generic type.
Define the generic type.
genCls = NET.GenericClass('System.Collections.Generic.List[]','System.Double');
Create the array.
genArr = NET.createArray(genCls,3)
genArr = List<System*Double>[][] with properties: Length: 3 LongLength: 3 Rank: 1 SyncRoot: [1×1 System.Collections.Generic.List<System*Double>[][]] IsReadOnly: 0 IsFixedSize: 1 IsSynchronized: 0
Create Nested Jagged Array
Create a jagged array of type
System.Double[][][]
.
netArr = NET.createArray('System.Double[][]',3)
netArr = Double[][][] with properties: Length: 3 LongLength: 3 Rank: 1 SyncRoot: [1x1 System.Double[][][]] IsReadOnly: 0 IsFixedSize: 1 IsSynchronized: 0
Input Arguments
typeName
— .NET array type name
string | character vector | NET.GenericClass
Fully specified .NET array type name, specified as a string, character vector, or
NET.GenericClass
object.
Example: 'System.Double[]'
Example: 'NET.GenericClass('System.Collections.Generic.List','System.Int32')'
m,n,p,...
— Number of elements in each dimension
array of integers
Number of elements in each dimension, specified as an array of integers.
Version History
Introduced in R2009a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)