探索 libstruct 对象
此示例说明如何显示和修改 libstruct 对象 c_struct 的信息。
加载包含 c_struct 定义的 shrlibsample 库。
if not(libisloaded('shrlibsample')) addpath(fullfile(matlabroot,'extern','examples','shrlib')) loadlibrary('shrlibsample') end
创建 libstruct 对象。对象 sc 是名为 lib.c_struct 的 MATLAB® 类的一个实例。
sc = libstruct('c_struct')sc =
c_struct with properties:
p1: 0
p2: 0
p3: 0
设置结构体字段值。
set(sc,'p1',100,'p2',150,'p3',200)
显示字段值。
get(sc)
p1: 100
p2: 150
p3: 200
使用 MATLAB 字段结构体语法修改值。
sc.p1 = 23; get(sc)
p1: 23
p2: 150
p3: 200