Main Content

matlab::data::MATLABString

Element type for MATLAB string arrays

Description

Use MATLABString to represent MATLAB® string arrays in C++. To be able to represent missing string array elements, MATLABString is defined as:

using MATLABString = optional<String>;

For more information on string arrays in MATLAB, see Create String Arrays.

Class Details

Namespace:

matlab::data

Include:

String.hpp

Examples

Pass String Array from MATLAB to MEX function

Create a string array in MATLAB and pass it to a C++ MEX function:

str(1) = "";
str(2) = "Gemini";
str(3) = string(missing)
result = myMexFcn(str);

In the MEX function, assign the input to an array of type matlab::data::MATLABString.

matlab::data::TypedArray<matlab::data::MATLABString> stringArray = inputs[0];

Pass String Array from MEX function to MATLAB

Create a string array in the MEX function and pass this array to MATLAB as output. The array defines text elements, an empty string, and a missing string element.

matlab::data::ArrayFactory factory;
outputs[0] = factory.createArray<MATLABString>({ 1,3 }, 
	{ matlab::data::MATLABString(u""), 
       matlab::data::MATLABString(u"Gemini"), 
       matlab::data::MATLABString() });

The result returned to MATLAB is a string array.

 result = 

  1×3 string array

    ""    "Gemini"    <missing>
Introduced in R2017b