Main Content

Pass .NET Data Types to MATLAB Functions

When you pass .NET data as input arguments to MATLAB® functions, the engine converts the data into equivalent MATLAB data types.

These tables show how the engine maps .NET data types to MATLAB data types.

Pass .NET Numeric Types to MATLAB

.NET Data Type (Scalar)

Resulting MATLAB Type (Scalar)

System.Double

double

System.Single

single

System.SByte

int8

System.Byte

uint8

System.Int16

int16

System.UInt16

uint16

System.Int32

int32

System.UInt32

uint32

System.Int64

int64

System.UInt64

uint64

System.Boolean

logical

Numerics.Complex

complex double
MATLAB does not support complex numbers for other numeric types.

MathWorks.MATLAB.Types.MATLABStruct

struct

.NET Data Type (1-D Vector)

Resulting MATLAB Type (1-D Vector)

System.Double[]

double

System.Single[]

single

System.SByte[]

int8

System.Byte[]

uint8

System.Int16[]

int16

System.UInt16[]

uint16

System.Int32[]

int32

System.UInt32[]

uint32

System.Int64[]

int64

System.UInt64[]

uint64

System.Boolean[]

logical

Numerics.Complex[]

complex double
MATLAB does not support complex numbers for other numeric types.

MathWorks.MATLAB.Types.MATLABStruct[]

struct[]

.NET Data Type (N-D Array)

Resulting MATLAB Type (N-D Array)

System.Double[,,...]

double

System.Single[,,...]

single

System.SByte[,,...]

int8

System.Byte[,,...]

uint8

System.Int16[,,...]

int16

System.UInt16[,,...]

uint16

System.Int32[,,...]

int32

System.UInt32[,,...]

uint32

System.Int64[,,...]

int64

System.UInt64[,,...]

uint64

System.Boolean[,,...]

logical

Numerics.Complex[,,...]

complex double
MATLAB does not support complex numbers for other numeric types.

MathWorks.MATLAB.Types.MATLABStruct[,,...]

struct[,,...]

Constants

Resulting MATLAB Value

System.Double.NaN

Result of NaN("double")

System.Single.NaN

Result of NaN("single")

System.Double.PositiveInfinity

Result of Inf("double")

System.Single.PositiveInfinity

Result of Inf("single")

System.Double.NegativeInfinity

Result of -Inf("double")

System.Single.NegativeInfinity

Result of -Inf("single")

Note

The .NET System.Decimal type is not supported for scalar, vector, or array arguments.

Pass .NET String and Character Types to MATLAB

.NET Data Type (Scalar)

Resulting MATLAB Type (Scalar)

System.String

string

System.Char

char

null System.String

<missing> value in string

.NET Data Type (1-D Vector)

Resulting MATLAB Type (1-D Vector)

System.String[]

string

System.Char[]

char

.NET Data Type (N-D Array)

Resulting MATLAB Type (N-D Array)

System.String[,,...]

string

System.Char[,,...]

char

Pass .NET Dictionary to MATLAB

To convert a .NET object to a MATLAB dictionary:

  • The type of the object implements the System.Collections.Generic.IDictionary<TKey,TValue> interface exactly once.

  • For each dictionary entry, the key (TKey) must be a numeric, boolean, or string type.

  • For each dictionary entry, the value (TValue) can be converted to a MATLAB data type using the conversion rules in Pass .NET Data Types to MATLAB Functions.

    The resulting dictionary must be a valid MATLAB dictionary. An example of an invalid dictionary is one that contains two values of different classes that are not heterogeneous.

For examples, see Use MATLAB Dictionary Objects in .NET.

.NET Data Type

Resulting MATLAB Type

System.Collections.Generic.Dictionary<TKey,TValue> if TKey and TValue can be converted keys and values in a MATLAB dictionary.

dictionary

The type of keys (TKey) and values (TValue) must be one of these types, resulting in these conversions:

.NET Type

C# Keyword

Resulting MATLAB Type

Restrictions

System.Booleanboollogical

None

System.SBytesbyteint8

None

System.Bytebyteuint8

None

System.Int16shortint16

None

System.UInt16ushortuint16

None

System.Int32intint32

None

System.UInt32uintuint32

None

System.Int64longint64

None

System.UInt64ulonguint64

None

System.Singlefloatsingle

None

System.Doubledoubledouble

None

System.Charcharstring

None

System.Stringstringstring

None

MathWorks.MATLAB.Types.MATLABObject

None

value or handle class

Not supported as keys

MathWorks.MATLAB.Types.MATLABStruct

None

struct

System.Objectobject

cell

Pass .NET System.Object to MATLAB

.NET Data Type

Resulting MATLAB Type

System.Object[]

1-D cell vector

System.Object[,,...]

N-D cell array

Pass .NET Handle and Value Objects to MATLAB

.NET Object TypeResulting MATLAB Type

MathWorks.MATLAB.Types.MATLABObject

scalar of underlying MATLAB type

MathWorks.MATLAB.Types.MATLABObject[]

1-D vector of underlying MATLAB type

MathWorks.MATLAB.Types.MATLABObject[,,...]

N-D array of underlying MATLAB type

Related Topics