Main Content

matlab::data::MATLABFieldIdentifier

C++ class used to identify field names in MATLAB struct array

Description

Class Details

Namespace:

matlab::data

Include:

MATLABFieldIdentifier.hpp

Constructors

Default Constructor

MATLABFieldIdentifier()

Description

Construct an empty MATLABFieldIdentifier.

Throws

None

Constructor

MATLABFieldIdentifier(std::string str)

Description

Construct a MATLABFieldIdentifier from std::string.

Parameters

std::string str

String that contains the field name.

Destructor

~MATLABFieldIdentifier()

Description

Destroy a MATLABFieldIdentifier.

Throws

None

Copy Constructors

MATLABFieldIdentifier(const MATLABFieldIdentifier& rhs)

Description

Creates a shared data copy of a MATLABFieldIdentifier object.

Parameters

const MATLABFieldIdentifier& rhs

Value to copy.

Throws

None

Copy Assignment Operators

MATLABFieldIdentifier& operator=(MATLABFieldIdentifier const& rhs)

Description

Assigns a shared data copy to a MATLABFieldIdentifier object.

Parameters

MATLABFieldIdentifier const& rhs

Value to move.

Returns

MATLABFieldIdentifier&

Updated instance.

Throws

None

Move Constructors

MATLABFieldIdentifier(MATLABFieldIdentifier&& rhs)

Description

Moves contents a MATLABFieldIdentifier object to a new instance.

Parameters

MATLABFieldIdentifier&& rhs

Value to move.

Throws

None

Move Assignment Operators

MATLABFieldIdentifier& operator=(MATLABFieldIdentifier&& rhs)

Parameters

MATLABFieldIdentifier&& rhs

Value to move.

Returns

MATLABFieldIdentifier&

Updated instance.

Throws

None

Destructor

~MATLABFieldIdentifier()

Description

Destroy a MATLABFieldIdentifier.

Other Operators

operator std::string

operator std::string() const

Returns

std::string

Representation of the MATLABFieldIdentifier object.

Throws

None

Free Functions

operator==

bool operator==(const MATLABFieldIdentifier& rhs) const

Description

Check if two MATLABFieldIdentifier objects are identical.

Parameters

const MATLABFieldIdentifier& rhs

Value to be compared.

Returns

bool

Returns true if the objects are identical. Otherwise, returns false.

Throws

None

Examples

Get Contents of Structure

Access the data in MATLAB® structures that are passed to C++ MEX functions or C++ Engine programs using the structure field name.

Here is a structure passed to a MEX function. The Date field contains the date when the structure is created, as returned by the datetime function. The Data field contains a numeric value.

s = struct("Date",string(datetime("today")),"Data",100);

In a MEX function, store the input as a StructArray. Use the getFieldNames member function to get a range of MATLABFieldIdentifier elements representing the structure field names. Use the second element to get the numeric data from the Data field. Store numeric data in a TypedArray with elements of type double.

matlab::data::StructArray inStruct(inputs[0]);
matlab::data::Range<matlab::data::ForwardIterator, matlab::data::MATLABFieldIdentifier const> 
    fields = inStruct.getFieldNames();
const matlab::data::TypedArray<double> data = inStruct[0][fields.begin()[1]];
double cppData = data[0];

Version History

Introduced in R2017b