Main Content

Limitations Using Structures

MATLAB Returns Pointers to Structures

MATLAB® returns pointers to structures. Return by value is not supported.

Struct Arrays not Supported for Input/Output Arguments

Passing a MATLAB struct array as an input or output argument to a function which modifies the C struct array is not supported.

Structure Cannot Contain Pointers to Other Structures

Nested structures or structures containing a pointer to a structure are not supported.

Requirements for MATLAB Structure Arguments

When you pass a MATLAB structure to an external library function, the field names must meet the following requirements.

  • Every MATLAB field name must match a field name in the library structure definition.

  • MATLAB structures cannot contain fields that are not in the library structure definition.

  • If a MATLAB structure contains fewer fields than defined in the library structure, MATLAB sets undefined fields to zero.

  • Field names are case-sensitive. For example, suppose that library mylib contains function myfunc with the following structure definition.

    struct S {
        double len;

    The field name is len. If you pass a structure to myfunc with the field name Len, MATLAB displays an error.

    S.Len = 100;

Requirements for C struct Field Names

When MATLAB loads a C struct definition, the field names in MATLAB are not case-sensitive. For example, when you load a library containing the following definition, MATLAB does not create two fields.

struct S {
    double Num;
    double num;

Related Topics