This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create C++ programs that work with MATLAB® data

The MATLAB Data API provides a way for applications running outside of MATLAB to work with MATLAB data through a MATLAB-neutral interface. The API uses modern C++ semantics and design patterns and avoids data copies whenever possible by using MATLAB copy-on-write semantics.


The MATLAB Data API supports C++11 features and is not compatible with the C Matrix API. You cannot mix functions from the MATLAB Data API with those in the C MEX API in a MEX file. Likewise, you cannot mix MATLAB Data API functions with functions in the MATLAB Engine API for C or the MATLAB C API to Read MAT-File Data in a standalone application.


matlab::data::ArrayFactoryC++ class to create arrays

Array Types

matlab::data::ArrayC++ base class for all array types
matlab::data::TypedArray<T>Templated C++ class to access array data
matlab::data::CellArrayC++ class to access MATLAB cell arrays
matlab::data::CharArrayC++ class to access MATLAB character arrays
matlab::data::EnumArrayC++ class to access MATLAB enumeration arrays
matlab::data::ObjectArrayC++ class to access MATLAB object arrays
matlab::data::SparseArray<T>Templated C++ class to access data in MATLAB sparse arrays
matlab::data::StringArrayC++ class to access MATLAB string arrays
matlab::data::StructArrayC++ class to access MATLAB struct arrays

Data Types

matlab::data::ArrayTypeC++ array type enumeration class
matlab::data::ArrayDimensionsType specifying array dimensions
matlab::data::EnumerationElement type for MATLAB enumeration arrays
matlab::data::MATLABFieldIdentifierC++ class used to identify field names in MATLAB struct array
matlab::data::MATLABStringElement type for MATLAB string arrays
matlab::data::ObjectElement type for MATLAB object arrays
matlab::data::optional<T>Templated C++ class representing optional values
matlab::data::StringType representing strings as std::basic_string<char16_t>
matlab::data::StructElement type for MATLAB struct arrays


matlab::data::Reference<T>Templated C++ class to get references to Array elements
matlab::data::Reference<MATLABString>C++ class to get reference to element of StringArray
matlab::data::Reference<Struct>C++ class to get reference to element of StructArray
matlab::data::Reference<Array>C++ class to get reference to Array
matlab::data::Reference<TypedArray<T>>Templated C++ class to get reference to TypedArray
matlab::data::Reference<SparseArray<T>>Templated C++ class to get reference to SparseArray
matlab::data::Reference<CharArray>C++ class to get reference to CharArray
matlab::data::Reference<EnumArray>C++ class to get reference to EnumArray
matlab::data::Reference<StructArray>C++ class to get reference to StructArray


matlab::data::TypedIterator<T>Templated C++ class to provide random access iterator
matlab::data::ForwardIterator<T>Templated C++ class to provide forward iterator support for StructArray field names
matlab::data::Range<ItType,ElemType>Templated C++ class to provide range-based operation support

Helper Functions

matlab::data::apply_visitorCall Visitor class on arrays
matlab::data::apply_visitor_refCall Visitor class on array references


matlab::ExceptionC++ base class for exceptions


Create Arrays with C++ MATLAB Data API

Create MATLAB array

Copy C++ MATLAB Data Arrays

The matlab::data::Array class supports both copy and move semantics.

Access C++ Data Array Container Elements

The C++ MATLAB Data API CellArray and StructArray types are containers for other MATLAB Data Arrays.

C++ Cell Arrays

To create a cell array, use the matlab::data::ArrayFactory createCellArray function.

Operate on C++ Arrays Using Visitor Pattern

The visitor design pattern is a useful technique for performing various operations on arrays.

MATLAB Data API Exceptions

The MATLAB Data API defines specific exception classes for MATLAB.


The MATLAB Data API defines specific types for working with MATLAB.

Was this topic helpful?