matlab::data::StructArray - C++ class to access MATLAB struct arrays - MATLAB (original) (raw)
C++ class to access MATLAB struct arrays
Description
Use StructArray
objects to work with MATLABĀ® struct arrays. To access a field for a single element in the array, use the field name. To create a StructArray
object, call createStructArray in the ArrayFactory
class.
Class Details
Constructors
Copy Constructors
StructArray(const StructArray& rhs)
StructArray(const Array& rhs)
Description
Creates a shared data copy of a StructArray
object.
Parameters
const StructArray& rhs | Value to copy. |
---|---|
const Array& rhs | Value specified asArrayType::STRUCT object. |
Throws
matlab::data::InvalidArrayTypeException | Type of input Array is not ArrayType::STRUCT. |
---|
Copy Assignment Operators
StructArray& operator=(const StructArray& rhs)
StructArray& operator=(const Array& rhs)
Description
Assigns a shared data copy to a StructArray
object.
Parameters
const StructArray& rhs | Value to copy. |
---|---|
const Array& rhs | Value specified asArrayType::STRUCT object. |
Returns
StructArray& | Updated instance. |
---|
Throws
matlab::data::InvalidArrayTypeException | Type of input Array is not ArrayType::STRUCT. |
---|
Move Constructors
StructArray(StructArray&& rhs)
Description
Moves contents of a StructArray
object to a new instance.
Parameters
StructArray&& rhs | Value to move. |
---|---|
Array&& rhs | Value specified asArrayType::STRUCT object. |
Throws
matlab::data::InvalidArrayTypeException | Type of input Array is not ArrayType::STRUCT. |
---|
Move Assignment Operators
StructArray& operator=(StructArray&& rhs)
Description
Assigns the input to this StructArray
object.
Parameters
StructArray&& rhs | Value to move. |
---|
Returns
StructArray& | Updated instance. |
---|
Destructor
~StructArray()
Description
Free memory for StructArray
object.
Member Functions
getFieldNames
Range<ForwardIterator, MatlabFieldIdentifier const> getFieldNames() const
Returns
Range<ForwardIterator, MatlabFieldIdentifier const> | Contains begin andend iterators that enable access to all fields in StructArray object. |
---|
getNumberOfFields
size_t getNumberOfFields() const
Examples
Assume that you have the following MATLAB structure.
s = struct('loc', {'east', 'west'}, 'data', {[1, 2, 3], [4., 5., 6., 7., 8.]})
Create a variable containing the data forloc
east
.
The following C++ code creates these variables.
#include "MatlabDataArray.hpp"
int main() { using namespace matlab::data; ArrayFactory factory;
StructArray S = factory.createStructArray({ 1,2 }, { "loc", "data" });
S[0]["loc"] = factory.createCharArray("east");
S[0]["data"] = factory.createArray<uint8_t>({ 1, 3 }, { 1, 2, 3 });
S[1]["loc"] = factory.createCharArray("west");
S[1]["data"] = factory.createArray<double>({ 1, 5 }, { 4., 5., 6., 7., 8. });
Reference<Array> val = S[0]["data"];
return 0;
}
Version History
Introduced in R2017b