Work with libstruct Objects

This example shows how to display information about a libstruct object.

Create libstruct Object

Create libstruct object sc.

sm.p1 = 476;
sm.p2 = -299;
sm.p3 = 1000;
sc = libstruct('c_struct',sm);

Class of libstruct Object

A libstruct object is an instance of a MATLAB® class called lib.c_struct.

  Name      Size                   Bytes  Class

sc         1x1                           lib.c_struct
sm         1x1                      396  struct array

Size of libstruct Object

Use the lib.c_struct class method structsize to obtain the size of a libstruct object.

ans = 

Accessing Fields of libstruct Object

The fields are properties of the lib.c_struct class. You can read and modify a field using the MATLAB set and get functions:

sc = libstruct('c_struct');
    p1: 100
    p2: 150
    p3: 200

You can also read and modify the fields by treating them like MATLAB structure fields:

sc.p1 = 23;
ans =
Was this topic helpful?