Main Content

libstruct オブジェクトの確認

この例では、libstruct オブジェクトc_structについての情報を表示し、このオブジェクトを変更する方法を説明します。

c_struct定義を含むshrlibsampleライブラリを読み込みます。

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

libstructオブジェクトを作成します。scオブジェクトは、lib.c_structと呼ばれる MATLAB クラスのインスタンスです。

sc = libstruct('c_struct')
sc = lib.c_struct

構造体フィールドの値を設定します。

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