Main Content

Pass clib.array to C++ Functions

MATLAB® provides the clib.array interface to wrap C++ native arrays and std::vector types in MATLAB objects. The term clib array refers to the MATLAB object representation of these C++ types.

A MATLAB clib array is defined only when the corresponding C++ native array or std::vector type is used by supported C++ constructs—function input and output arguments and data members. The library header files must contain the definition of the array element type. The constructs must be supported by MATLAB and included when building the MATLAB interface to the C++ library.

For information about creating a MATLAB array of C++ objects or converting an MATLAB array to a C++ array object, see Create MATLAB Array of C++ Objects.

MATLAB C++ Object Array Properties

MATLAB arrays created with clibArray or clibConvertArray have these properties.

Property

TypeAccess

Description

Dimensions

double vectorRead-only

Dimensions of the C++ array. For example, [2 5 3] specifies a 2-by-5-by-3 array.

Resizable

logical scalarRead-only

  • true — You can add or remove elements.

  • false — You cannot add or remove elements.

MATLAB C++ Object Array Methods

MATLAB arrays created with clibArray or clibConvertArray have these methods.

Method

Syntax

Description

append

append([element])

Add an optionally specified element to the end of the array.

For a primitive MATLAB clib array, if you do not specify an input argument, then the method appends a zero value.

For a class-type MATLAB clib array, if you do not specify an input argument, then the method appends an object created by the class-type default constructor. If the class-type default constructor is deleted, a run-time error occurs.

removeLast

removeLast

Remove the last element of the array. If the MATLAB clib array is empty, a run-time error occurs.

double

double

Convert to double precision.

int8

int8

Convert to int8.

uint8

uint8

Convert to uint8.

int16

int16

Convert to int16.

uint16

uint16

Convert to uint16.

int32

int32

Convert to int32.

uint32

uint32

Convert to uint32.

int64

int64

Convert to int64.

uint64

uint64

Convert to uint64.

logical

logical

Convert to logical.

struct (since R2024b)

struct

Convert to structure.

Memory Management

The memory for MATLAB arrays created with clibArray or clibConvertArray is managed by MATLAB. You do not need to explicitly release the memory for clib arrays. For more information about releasing memory for C++ objects from MATLAB, see clibRelease.

See Also

|

Topics