Main Content

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 =

	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