C++ class to access MATLAB object arrays
Use ObjectArray
objects to access MATLAB® object arrays. To create an ObjectArray
, call createArray
in the
ArrayFactory
class using this syntax:
template <typename ItType, typename T> TypedArray<T> createArray(ArrayDimensions dims, ItType begin, ItType end)
To create a scalar object, call createScalar
using this syntax:
ObjectArray createScalar(const Object& val);
ObjectArray
is defined as:
using ObjectArray = TypedArray<Object>;
Namespace: | matlab::data |
Include: | ObjectArray.hpp |
You cannot combine elements of an ObjectArray
into a heterogeneous
array.
If the class defining the Object
overrides
subsref
or subsasgn
, then you cannot
access the elements of the ObjectArray
.
ObjectArray
Create an ObjectArray
from myObject
class
objects. The iterators are pointers to the beginning and the end of the
array.
class myObject { public: const std::vector<matlab::data::Object>& getObjs() const { return fObjs; } private: std::vector<matlab::data::Object> fObjs; }; const myObject& a1; const myObject& a2; matlab::data::ArrayFactory factory; const auto& objs = a1.getObjs(); matlab::data::ObjectArray arr1 = factory.createArray({1,2}, objs.begin(), objs.end());
ObjectArray
Iterate using a range-based for loop through an ObjectArray
and
retrieve the objects in the array.
std::vector<matlab::data::Object> fObjs; // Use a range-based for loop to iterate over the objects. for (const auto& o : objs) { fObjs.push_back(o); }
C++ MEX and C++ Engine applications can get and set property values on MATLAB objects. For information on how to access MATLAB objects in these applications, see these topics:
MATLAB Objects in MEX Functions - for C++ MEX applications
Get MATLAB Objects and Access Properties - for C++ Engine applications