This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Explore libstruct Objects

This example shows how to display information about and modify a libstruct object, c_struct.

Load the shrlibsample library containing the c_struct definition.

if not(libisloaded('shrlibsample'))
    addpath(fullfile(matlabroot,'extern','examples','shrlib'))
    loadlibrary('shrlibsample')
end

Create the libstruct object. Object sc is an instance of a MATLAB class called lib.c_struct.

sc = libstruct('c_struct')
sc =

	lib.c_struct

Set structure field values.

set(sc,'p1',100,'p2',150,'p3',200)

Display field values.

get(sc)
    p1: 100
    p2: 150
    p3: 200

Modify values using MATLAB field structure syntax.

sc.p1 = 23;
get(sc)
    p1: 23
    p2: 150
    p3: 200