Main Content

Define Missing Direction Property

R2026b

In C++, pointer arguments can be used to pass and return data from a function. Use the Direction property of a clibgen.api.InputArgumentDefinition object when defining arguments in a MATLAB® interface.

You typically specify this property when programmatically defining or updating argument behavior in an interface definition. The Direction value determines how arguments are represented in the generated MATLAB function signature.

The Direction property has one of these values:

  • "input" — Input argument only

    If a pointer argument is used to pass data to the function, then it appears as an input argument in the MATLAB signature.

    The Direction value for C-string parameters must be input.

  • "output" — Output argument only

    If a pointer argument is used to retrieve data from the function, then it must appear as an output argument in the MATLAB signature.

  • "inputoutput" — Input and output argument

    If a pointer argument is used to both pass and return data, then it must appear as both an input argument and an output argument.

Note

Default arguments with direction specified as OUT are not supported. Define these with Direction as "input" or "inputoutput" in the clibgen.api.InterfaceDefinition object.

For example, suppose that a C++ function passData has the following signature. The argument data might be an input to the function, the return value of the function, or input that the function modifies and returns. The documentation of the function tells you how the function uses the argument data.

void passData(double *data); 

Assuming data is a scalar double value, this table shows the MATLAB signature based on its role.

C++ Role for dataMATLAB SignatureSet Argument Direction

Input data only to passData

passData(data) 
arg = fcn.CPPInputs([fcn.CPPInputs.Name] == "data");
arg.Direction = "input";

Return data only from passData

[data] = passData() 
arg = fcn.CPPInputs([fcn.CPPInputs.Name] == "data");
arg.Direction = "output";

Input and output data for passData

[data] = passData(data) 
arg = fcn.CPPInputs([fcn.CPPInputs.Name] == "data");
arg.Direction = "inputoutput";

To return multiple outputs, suppose that function calcXY has this signature:

void calcXY(double *data, double *X, double *Y);
C++ Role for ParametersMATLAB SignatureSet Argument Direction

data is input to the function.

[X,Y] = calcXY(data,X,Y) 
arg = fcn.CPPInputs([fcn.CPPInputs.Name] == "data");
arg.Direction = "input";
X and Y are input and output parameters.
argX = fcn.CPPInputs([fcn.CPPInputs.Name] == "X");
argX.Direction = "inputoutput";
argY = fcn.CPPInputs([fcn.CPPInputs.Name] == "Y");
argY.Direction = "inputoutput";

See Also

Objects

Topics