Main Content

clibConvertArray

Convert MATLAB fundamental or struct array to MATLAB array of C++ objects

Since R2020a

Description

cArray = clibConvertArray(elementTypeName,A) converts MATLAB® array A to a clib array, a MATLAB object representing a C++ object of type elementTypeName. The dimensions of cArray are the same as A. Each element of cArray is initialized by the corresponding element of A.

Like clibArray, you can only construct an array if the library requires that type.

The memory of cArray is owned by MATLAB. To release the memory, call clibRelease.

example

Examples

collapse all

Suppose that you have an interface to a C++ library libname. Convert a MATLAB array of double.

a = [1 2 3 4];
arr = clibConvertArray("clib.libname.Double", a);
class(arr)
ans =
       'clib.array.libname.Double'

Suppose that you have a library libname containing a C++ structure named MyStruct defined by this code.

struct MyStruct {
    double a;
    };

You want to pass this MATLAB struct array mArray to the library.

mArray(1).a = 5;
mArray(2).a = 10;

Create a clib.array object named myStructArray. Use this object for arguments of type clib.libname.MyStruct.

myStructArray = clibConvertArray("clib.libname.MyStruct",mArray);
class(myStructArray)
ans =
       'clib.array.libname.MyStruct'

Input Arguments

collapse all

C++ type, specified as a string or a character vector. For more information, see C++ to MATLAB Data Type Mapping. Supported types are:

MATLAB converts the names of fundamental C++ types to upper camel case. For example, elementTypeName for C++ type signed int is SignedInt.

The type is a fully qualified C++ type name. For example, if a library libname defines a class myclass, then elementTypeName is clib.libname.myclass.

C++ class names are not supported.

Example: clib.libname.Double

Data Types: char | string

MATLAB array, specified as numeric MATLAB type.

Version History

Introduced in R2020a

expand all