Define Missing Size Property
R2026bWhen a C++ function uses pointer arguments to represent array data, MATLAB® needs explicit size information to convert that data safely. The
Size property specifies the dimensions of pointer and array arguments
so MATLAB can correctly interpret scalars, vectors, and multidimensional arrays when
generating a C++ interface. In this context, Size is not inferred from
the C++ signature itself. Instead, it is a property of the argument definition
object—specifically, clibgen.api.InputArgumentDefinition or clibgen.api.OutputArgumentDefinition. You set the Size
property to describe how MATLAB interprets the dimensions of the data associated with that argument.
For information about how MATLAB converts C/C++ data into equivalent MATLAB data types, see C++ to MATLAB Data Type Mapping.
Note
Pointers representing arrays of C++ class objects can only be used as scalars. Define
Size as 1 in the clibgen.api.InterfaceDefinition object.
The following example C++ signatures show you how to specify the shape of an argument. In these tables, the descriptions for the functions in the C++ Signature and Role of Pointer column are based on assumed knowledge of the arguments. The signature does not provide this information.
In these examples, function F is a FunctionDefinition
object and argument A is an InputArgumentDefinition or
OutputArgumentDefinition object of the function. Use the
InputArgumentDefinition
define or
OutputArgumentDefinition
define function
to complete the argument definitions.
Note
Before R2026b: Use defineArgument functions
in the library definition file to set <SHAPE>, <DIRECTION>, and <MLTYPE>
values
Define Pointer Argument to Fixed Scalar
For fixed-width scalar integer and scalar object types, set the
Size property to 1.
| C++ Signature and Role of Pointer |
define Argument Values |
|---|---|
The input to this function is a scalar pointer
| For argument A = F.CPPInputs; A.Size=1; |
The input to this function is a scalar pointer to class
| For argument A = F.CPPInputs; A.Size=1; |
Define Pointer Argument
For pointer arguments, set Size to the length of each
dimension.
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a pointer to an integer array of length
| For argument A = F.CPPInputs;
A(1).Size="m"; |
The input to this function is a pointer to a fixed-length array
| For argument A = F.CPPInputs; A.Size=4; |
The input to this function is a pointer to a two-dimensional integer
matrix | For argument A = F.CPPInputs; A(1).Size= ["m","n"]; |
The input to this function is a pointer to a two-dimensional matrix
| For argument A = F.CPPInputs; A.Size=6; |
The input to this function is a pointer to a three-dimensional matrix
| For argument A = F.CPPInputs; A(1).Size= ["m","n","p"]; |
Define Array Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a one-dimensional array
| For argument A = F.CPPInputs;
A(1).Size= "len"; |
The input to this function is a two-dimensional array
| For argument A = F.CPPInputs; A(1).Size=["len","typeSz"]; |
Define Output Pointer Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a pointer to an array of length
| For output argument A = F.CPPOutput;
A.Size= "len"; |
The input to this function is a pointer to an array of length
| For output argument A = F.CPPOutput; A.define(Size="len",DeleteFcn="CustomDeleteFcn"); |
The output argument of this function is a pointer to a fixed-length array. | For output argument A = F.CPPOutput; A.Size=5; |
The output argument of this function is a pointer to a 2-by-2 array. | For output argument A = F.CPPOutput; A.Size=[2,2]; |
The output argument of this function is a pointer to a 1-by-2 vector of
type double. The library provides a function named
| For output argument A = F.CPPOutput;
A.define(Size=2,DeleteFcn="CustomDeleteFcn") |
The output argument of this function is a pointer to a 1-by-2 vector of
type | For output argument A = F.CPPOutput;
A.define(Size=2,DeleteFcn="CustomDeleteFcn"); |
Define Additional Output Arguments
| C++ Signature |
define Argument Values |
|---|---|
This function returns an integer value and the value to which input
argument | For argument A = F.CPPInputs; A.define(Direction="output",Size=1,MATLABType="int32"); |
To call the function built into interface
[out1, out2] = clib.libname.getValues | |
Define Scalar Object Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a pointer to class
| For the A = F.CPPInputs; A.Size=1; |
The input to this function is a pointer to class
| For argument A = F.CPPInputs; A(1).Size=1; |
The input to this function is a pointer to class
| For argument A = F.CPPInputs; A.Size=1; |
The input to this function is a pointer to class
| For argument A = F.CPPInputs; A(1).Size=1; |
Define Matrix Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a pointer to an integer vector of length
| For argument A = F.CPPInputs; A(1).define(Direction="inputoutput",Size="len; |
The input to this function is a reference to an integer array of length
| For argument A = F.CPPInputs;
A(1).Size="len"; |
The input to this function is a pointer to an integer vector of length
| For argument A = F.CPPInputs;
A(1).Size="len"; |
The input to this function is a reference to an integer array of length
| For argument A = F.CPPInputs;
A(1).Size="len"; |
Define String Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a C-style string. | For argument A = F.CPPInputs; A(1).define(MATLABType="string", ... Size="nullTerminated"); |
The return value for this function is a string. | For output argument A = F.CPPOutput; A(1).define(MATLABType="string",Size="nullTerminated"); |
The return value for this function is a string of length
|
MATLAB defines argument
A = F.CPPOutput; A(1).define(MATLABType="string", ... Size="nullTerminated",NumElementsInBuffer="buf"); |
The input to this function is a string specified by length
| For argument A = F.CPPInputs; A(1).define(MATLABType="char",Size="len"); |
The input to this function is an array of type | For argument A = F.CPPInputs; A(1).define(MATLABType="int8",Size="len"); |
The return value for this function is a scalar of characters. | For output argument A = F.CPPOutput;
A.define(MATLABType="char",Size=1); |
The return value for this function is a 2 element character vector. | For output argument |
The return value for this function is a 2 element character vector. The
library provides a function named | For output argument A = F.CPPOutput; A.define(MATLABType="char",Size=2, ... DeleteFcn="CustomDeleteFcn"); |
The type of the return value for this function is
| For output argument A = F.CPPOutput;
A.define(MATLABType="int8",Size=1); |
This function updates the input argument | For argument |
The input to these functions is an array of C-string of size
| For argument |
The input to these functions is a | Set the |
The input to this function is a fixed-size array of C-string. | For argument |
The input to this function is a fixed-size | Set the |
Define Typed Pointer Argument
| C++ Signature |
define Argument Values |
|---|---|
The input to this function is a pointer to typedef
| For argument A = F.CPPInputs;
A.define(Direction="input",Size=1);
|
Use Property or Method as Size
You can use a public nonstatic C++ data member (property) as the
Size property for the return type of a nonstatic method or another
nonstatic data member (property) in the same class. The property must be defined as an
integer (C++ type int). Similarly, you can use static C++ data members as
a Size property for a return type of a static method or another static
data member in the same class.
You can use a public, nonstatic C++ method as the Size property for
a nonstatic property or for the return type of a nonstatic method in the same class. The
method must be fully implemented, without input arguments, and the return type must be
defined as a C++ type int.
You can use a combination of arguments, properties, and methods as the
Size property for a method return type. If the specified
Size exists as both a parameter and a method or property, then
parameters take precedence. In this case Size is treated as a
parameter.
| C++ Signature |
Size Values |
|---|---|
The size of data member | For property |
The size of the array returned by | For the return value of method |
The size of the array returned by | For the return value of method |
See Also
Objects
clibgen.api.InterfaceDefinition|clibgen.api.InputArgumentDefinition|clibgen.api.OutputArgumentDefinition