The following table lists the data conversion rules used when converting native .NET types to MATLAB® arrays.
Note: The conversion rules listed in these tables apply to scalars, vectors, matrices, and multidimensional arrays of the native types listed. |
Conversion Rules: Managed Types to MATLAB Arrays
Native .NET Type | MATLAB Array | Comments |
---|---|---|
|
| — |
|
| Available only when the |
|
| |
|
| |
|
| |
|
| |
|
| None |
|
| None |
The following table lists the data conversion rules used when converting MATLAB arrays to native .NET types.
Note: The conversion rules apply to scalars, vectors, matrices, and multidimensional arrays of the listed MATLAB types. |
Conversion Rules: MATLAB Arrays to Managed Types
MATLAB Type | .NET Type (Primitive) | .NET Type (Class) | Comments |
---|---|---|---|
| N/A |
| Cell and struct arrays have no corresponding .NET type. |
| N/A |
| |
|
|
| |
|
|
| Default is type double. |
|
|
| |
|
|
| Not supported |
|
|
| Not supported |
|
|
| Not supported |
|
|
| None |
|
|
| None |
Function handle | N/A | N/A | None |
Object | N/A | N/A | None |
In order to create .NET interfaces that describe the type-safe API of a MATLAB Compiler SDK™ generated component, you must decide on the .NET types used for input and output parameters.
When choosing input types, consider how .NET inputs become MATLAB types. When choosing output types, consider the inverse conversion
The following tables list the data conversion results and rules used to convert .NET types to MATLAB arrays and MATLAB arrays to .NET types.
Note:
Invalid conversions result in a thrown |
Conversion Results: .NET Types to MATLAB Types
.NET Type | Converts to MATLAB Type |
---|---|
| numeric |
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Scalar .NET struct | MATLAB struct constructed from public instance
fields of the .NET struct |
.NET struct [ N ] | MATLAB struct |
.NET struct [ | MATLAB struct [ |
native.MWStructArray | struct |
native.MWCellArray | cell |
Hashtable | struct |
Dictionary <K ,V >Where | struct |
ArrayList | cell |
Any other .NET type in the default application domain | .NET object |
Any other serializable .NET type in a non-default application domain | .NET object |
Conversion Rules: MATLAB Numeric Types to .NET Types
To Convert This MATLAB Type: | To this: | Follow these rules: |
---|---|---|
numeric | Scalar | The type must be scalar in MATLAB. For example, a 1 X
1 |
Vector | The type must be a vector in MATLAB. For example, a 1
X | |
-dimensional
array | The |
Tip
When converting MATLAB |
Caution .NET types are not as flexible as MATLAB types. Take care and test appropriately with .NET outputs before integrating data into your applications. |
Conversion Rules: MATLAB Char Arrays to .NET Types
To Convert This MATLAB Type: | To this: | Follow these rules: |
---|---|---|
char | Char | The char must be scalar. |
Char array | The | |
String | MATLAB | |
String array | The |
Conversion Rules: MATLAB Logical Arrays to .NET Types
To Convert This MATLAB Type: | To this: | Follow these rules: |
---|---|---|
logical | Boolean | The logical must be scalar. |
Boolean[] | The MATLAB | |
Boolean array | The |
Conversion Rules: Cell Array to .NET Types
To Convert This MATLAB Type: | To this: | Follow these rules: |
---|---|---|
cell | System.Array | The |
ArrayList | The MATLAB cell array must be a vector.
|
Caution
If the MATLAB Let C = {[1,2,3], {[1,2,3]},'Hello world'} % be a cell C can be converted to an object[1,3] where object[1,1] contains int[,] object[1,2] contains
an object[1,1] whose first element in an int[,]
object[1,3] contains char[,] . |
Note:
Any nested cell array is converted to a |
Conversion Rules: Struct to .NET Types
To Convert This MATLAB Type: | To this: | Follow these rules: |
---|---|---|
struct | .NET struct | The name and number of public fields in the specified .NET struct must match the name and number of fields in the MATLAB struct. |
Hashtable | A scalar |
Conversion Rules: .NET Objects in MATLAB to .NET Native Objects
To Convert this MATLAB Type: | To this: | Follow these rules: |
---|---|---|
.NET object | Type or super-type of the containing object | A .NET object in MATLAB can only be converted to a type or a super-type. |
A native .NET string is converted to a 1
-by-N
MATLAB character
array, with N
equal to the length of the
.NET string.
An array of .NET strings (string[]
) is converted
to an M
-by-N
character
array, with M
equal to the number of elements
in the string ([]
) array and N
equal
to the maximum string length in the array.
Higher dimensional arrays of String
are similarly
converted.
In general, an N
-dimensional array
of String
is converted to an N
+1
dimensional MATLAB character
array with appropriate zero padding where supplied strings have different
lengths.
The MATLAB Compiler SDK product does not support the following MATLAB array types because they are not CLS-compliant:
int8
uint16
uint32
uint64
Note: While it is permissible to pass these types as arguments to a MATLAB Compiler SDK component, it is not permissible to return these types, as they are not CLS compliant. |