MATLAB® provides an interface, clib.array
, which wraps C++ native
arrays and std::vector
types. The term clib array
refers to the MATLAB representation of these C++ types.
A MATLAB clib array is only defined when the corresponding C++ native array or
std::vector
is used by supported C++ constructs—function input and
output arguments and data members. The provided headers must contain the definition of the
element type. The construct must be supported by MATLAB and not dropped when building the interface.
To create a MATLAB object to pass to a C++ function, call the MATLAB
clibArray
function. For example, suppose that your library libname
defines a
class myclass
. In MATLAB, you refer to this class as clib.libname.myclass
. To
create an array of five myclass
objects:
myclassArray = clibArray('clib.libname.myclass',5);
The type of the MATLAB array myclassArray
is
clib.array.libname.myclass
.
You can use an existing MATLAB array as a C++ array object. Call the clibConvertArray
function.
MATLAB arrays created with clibArray
or
clibConvertArray
have these properties.
Property | Type | Access | Description |
---|---|---|---|
| double vector | read-only | C++ dimensions of the array |
| logical scalar | read-only |
|
MATLAB arrays created with clibArray
or
clibConvertArray
have these methods.
Method | Signature | Description |
---|---|---|
| append([element]) | Add an optionally specified element to the end of the array. For a primitive MATLAB clib array, if there is no input argument, then a zero value is appended. For a class-type MATLAB clib array, if there is no input argument, then the class-type default constructor is appended. If the class-type default constructor is deleted, a runtime error occurs. |
| removeLast | Remove the last element of the array. If the MATLAB clib array is empty, a runtime error occurs. |
| double | Convert to double precision. |
|
| Convert to |
|
| Convert to |
|
| Convert to |
|
| Convert to |
|
| Convert to |
|
| Convert to |
|
| Convert to |
|
| Convert to |
| logical | Convert numeric values to logical. |
The memory for MATLAB arrays created with clibArray
or
clibConvertArray
is owned by MATLAB. To release the memory, call clibRelease
.
clibArray
| clibConvertArray
| clibRelease