Main Content

matlab::mex::ArgumentList

Container for inputs and outputs from C++ MEX functions

Description

C++ MEX functions pass inputs and outputs as matlab::data::Array objects contained in matlab::mex::ArgumentList objects. The MexFunction::operator() accepts two arguments, one for inputs and one for outputs, defined as matlab::mex::ArgumentList.

ArgumentList is a wrapper enabling iteration over the underlying collections holding the input and output data.

Class Details

Namespace:

matlab::mex

Include:

mex.hpp

Member Functions

operator[ ]

matlab::data::Array operator[](size_t idx)

Enables [] indexing into the elements of an ArgumentList.

Parameters

size_t idx

Index into the elements of the input array, which are the input arguments to the MEX function
Returns

matlab::data::Array

Iterator pointing to the first element in the ArgumentList array

Examples

Call a MEX function from MATLAB® with an array, a scalar, and a character vector as inputs and a single output:

a = myMEXFunction(array, scalar, 'character vector')

Assign the first input argument to a TypedArray, the second input to a scalar const double (assume both are of type double in MATLAB), and the third input as a matlab::data::CharArray.

void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
    matlab::data::TypedArray<double> inArray = inputs[0];
    const double inScalar = inputs[1][0];
    matlab::data::CharArray inChar = inputs[2];
    result = ...
    outputs[0] = result;
}

begin

iterator_type begin()

Returns an iterator pointing to the first element in the ArgumentList array.

Returns

iterator_type

Iterator pointing to the first element in the ArgumentList array

Examples

Build a vector from the input arguments.

void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
    std::vector<matlab::data::TypedArray<double>> vectorDoubles(inputs.begin(), inputs.end());
    ...
}

end

iterator_type end()

Returns an iterator pointing past the last element in the ArgumentList array.

Returns

iterator_type

Iterator pointing past the last element in the ArgumentList array

size

size_t numArgs size()

Returns the number of elements in the argument list. Use to check the number of inputs and outputs specified at the call site.

Returns

size_t

Size of the ArgumentList array

Examples

Determine if the MEX function is called with three input arguments.

class MexFunction : public matlab::mex::Function {
public:
    void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
    if (inputs.size() == 3) {
        // MEX function called with three input arguments
        ...
    }
}

empty

bool empty()

Returns logical value indicating if argument list is empty.

Returns

bool

Returns logical true if the argument list is empty (size() == 0)

Examples

Determine if the MEX function is called with no input arguments.

class MexFunction : public matlab::mex::Function {
public:
    void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
    if (inputs.empty()) {
        // MEX function called with no input arguments
        ...
    }
}
Introduced in R2018a