Main Content

Data Type Mappings Between C++ and Strongly Typed MATLAB Code

C++ to MATLAB

This table lists the data type mapping of C++ data types into strongly typed MATLAB® data types.

DescriptionC++ Data TypeMATLAB Data Type Representation
Real double scalar

double

(1, 1) double {mustBeReal}

Real double vector

std::vector<double>

(1, :) double {mustBeReal}

Complex double scalar

Note

Can be passed to MATLAB as plain real through C++ overloading

std::complex<double>

(1, 1) double

Complex double vector

Note

Can be passed to MATLAB as plain reals through C++ overloading

std::vector<std::complex<double>>

(1, :) double

Real single scalar

float

(1, 1) single {mustBeReal}

Real single vector

std::vector<float>

(1, :) single {mustBeReal}

Complex single scalar

Note

Can be passed to MATLAB as plain real through C++ overloading

std::complex<float>

(1, 1) single

Complex single vector

Note

Can be passed to MATLAB as plain reals through C++ overloading

std::vector<std::complex<float>>

(1, :) single

Real integer scalars

int8_t

int16_t

int32_t

int64_t

uint8_t

uint16_t

uint32_t

uint64_t

(1, 1) int8 {mustBeReal}

(1, 1) int16 {mustBeReal}

(1, 1) int32 {mustBeReal}

(1, 1) int64 {mustBeReal}

(1, 1) uint8 {mustBeReal}

(1, 1) uint16 {mustBeReal}

(1, 1) uint32 {mustBeReal}

(1, 1) uint64 {mustBeReal}

Real integer vectors

std::vector<int8_t>

std::vector<int16_t>

std::vector<int32_t>

std::vector<int64_t>

std::vector<uint8_t>

std::vector<uint16_t>

std::vector<uint32_t>

std::vector<uint64_t>

(1, :) int8 {mustBeReal}

(1, :) int16 {mustBeReal}

(1, :) int32 {mustBeReal}

(1, :) int64 {mustBeReal}

(1, :) uint8 {mustBeReal}

(1, :) uint16 {mustBeReal}

(1, :) uint32 {mustBeReal}

(1, :) uint64 {mustBeReal}

Complex integer scalars

std::complex<int8_t>

std::complex<int16_t>

std::complex<int32_t>

std::complex<int64_t>

std::complex<uint8_t>

std::complex<uint16_t>

std::complex<uint32_t>

std::complex<uint64_t>

(1, 1) int8

(1, 1) int16

(1, 1) int32

(1, 1) int64

(1, 1) uint8

(1, 1) uint16

(1, 1) uint32

(1, 1) uint64

Complex integer vectors

std::vector<std::complex<int8_t>>

std::vector<std::complex<int16_t>>

std::vector<std::complex<int32_t>>

std::vector<std::complex<int64_t>>

std::vector<std::complex<uint8_t>>

std::vector<std::complex<uint16_t>>

std::vector<std::complex<uint32_t>>

std::vector<std::complex<uint64_t>>

(1, :) int8

(1, :) int16

(1, :) int32

(1, :) int64

(1, :) uint8

(1, :) uint16

(1, :) uint32

(1, :) uint64

Logical scalar

bool

(1, 1) logical

Logical vector

std::vector<bool>

(1, :) logical

Char scalar

char16_t

(1, 1) char

Char vector

std::u16string

(1, :) char

String

std::u16string

(1, 1) string

String vector

std::vector<std::u16string>

(1, :) string

Enum scalar

matlab::data::Array containing matlab::data::ArrayType ENUM

(1, 1) MyEnumClass

Enum vector

matlab::data::Array containing matlab::data::ArrayType ENUM

(1, :) MyEnumClass

MATLAB to C++

The following table lists the data type mapping of strongly typed MATLAB data types to C++ data types.

DescriptionMATLAB Data TypeC++ Data Type Representation
Real double scalar

(1, 1) double {mustBeReal}

double or vector<double>

Real double vector

(1, :) double {mustBeReal}

std::vector<double>

Complex double scalar

Note

Stored as a complex number, even if result is real

(1, 1) double

std::complex<double>

Complex double vector

Note

Stored in MATLAB Data Array if result is real

(1, :) double

matlab::data::Array

If result contains DOUBLE or COMPLEX_DOUBLE:

matlab::data::ArrayType

Real single scalar

(1, 1) single {mustBeReal}

float

Real single vector

(1, :) single {mustBeReal}

std::vector<float>

Complex single scalar

(1, 1) single

std::complex<float>

Complex single vector

(1, :) single

matlab::data::Array

If result contains SINGLE or COMPLEX_SINGLE:

matlab::data::ArrayType

Real integer scalars

(1, 1) int8 {mustBeReal}

(1, 1) int16 {mustBeReal}

(1, 1) int32 {mustBeReal}

(1, 1) int64 {mustBeReal}

(1, 1) uint8 {mustBeReal}

(1, 1) uint16 {mustBeReal}

(1, 1) uint32 {mustBeReal}

(1, 1) uint64 {mustBeReal}

int8_t

int16_t

int32_t

int64_t

uint8_t

uint16_t

uint32_t

uint64_t

Real integer vectors

(1, :) int8 {mustBeReal}

(1, :) int16 {mustBeReal}

(1, :) int32 {mustBeReal}

(1, :) int64 {mustBeReal}

(1, :) uint8 {mustBeReal}

(1, :) uint16 {mustBeReal}

(1, :) uint32 {mustBeReal}

(1, :) uint64 {mustBeReal}

std::vector<int8_t>

std::vector<int16_t>

std::vector<int32_t>

std::vector<int64_t>

std::vector<uint8_t>

std::vector<uint16_t>

std::vector<uint32_t>

std::vector<uint64_t>

Complex integer scalars

(1, 1) int8

(1, 1) int16

(1, 1) int32

(1, 1) int64

(1, 1) uint8

(1, 1) uint16

(1, 1) uint32

(1, 1) uint64

std::complex<int8_t>

std::complex<int16_t>

std::complex<int32_t>

std::complex<int64_t>

std::complex<uint8_t>

std::complex<uint16_t>

std::complex<uint32_t>

std::complex<uint64_t>

Complex integer vectors

(1, :) int8

(1, :) int16

(1, :) int32

(1, :) int64

(1, :) uint8

(1, :) uint16

(1, :) uint32

(1, :) uint64

matlab::data::Array

If result contains INT8, COMPLEX_INT8, INT16, COMPLEX_INT16, INT32, COMPLEX_INT32, INT64, COMPLEX_INT64, UINT8, COMPLEX_UINT8, UINT16, COMPLEX_UINT16, UINT32, COMPLEX_UINT32, UINT64, or COMPLEX_UINT64:

matlab::data::ArrayType

Logical scalar

(1, 1) logical

bool

Logical vector

(1, :) logical

std::vector<bool>

Char scalar

(1, 1) char

char16_t

Char vector

(1, :) char

std::u16string

String

(1, 1) string

std::u16string

String vector

(1, :) string

std::vector<std::u16string>

Enum scalar

(1, 1) MyEnumClass

matlab::data::Array containing ENUM matlab::data::ArrayType

Enum vector

(1, :) MyEnumClass

matlab::data::Array containing ENUM matlab::data::ArrayType

MATLAB cell scalar

(1, 1) cell

matlab::data::Array containing CELL matlab::data::ArrayType

MATLAB cell vector

(1, :) cell

matlab::data::Array containing CELL matlab::data::ArrayType

MATLAB struct

(1, 1) struct

matlab::data::Array containing STRUCT matlab::data::ArrayType

MATLAB struct

(1, :) struct

matlab::data::Array containing STRUCT matlab::data::ArrayType

See Also

|

Related Topics