Quantcast

Documentation Center

  • Trial Software
  • Product Updates

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 an instance of a MATLAB® class called lib.c_struct.

whos
  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.

sc.structsize
ans = 
		16

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');
set(sc,'p1',100,'p2',150,'p3',200);
get(sc)
    p1: 100
    p2: 150
    p3: 200

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

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