Main Content

MATLAB Data API for C++

Use the MATLAB® Data API to read and write MATLAB data from C++ programs

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 modern C++ features and is not compatible with the C Matrix API. You cannot mix functions from the MATLAB Data API with those in the C Matrix API and C MEX API in a MEX file. Likewise, you cannot mix MATLAB Data API functions with functions in the C Engine API, described in Call MATLAB from C, or the C MAT-File API, described in Write C Programs to Read MAT-File Data.


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::ColumnMajorC++ class to create iterators and ranges that iterate in column-major order
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::RowMajorC++ class to create iterators and ranges that iterate in row-major order
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 in memory order
matlab::data::ColumnMajorIterator<T>Templated C++ class to provide column-major random access iterator
matlab::data::RowMajorIterator<T>Templated C++ class to provide row-major 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