| Programming with MATLAB |
資産subsrefメソッド
subsrefメソッドは、1から始まる数値インデックスと構造体フィールド名を使ったインデックスを使って、資産オブジェクトの中に含まれる日にアクセスします。
外側のswitchステートメントは、インデックスが、数値、または、フィールド名のどちらかを使ったものであるかを判断するものです。内側のswitch
ステートメント は、インデックスを適切な値に射影します。
MATLABは、サブスクリプトを使ったリファレンスをあるオブジェクト(たとえば、A(i),
A{i}, A.fieldname)にするときに、subsrefを呼びます。
function b = subsref(a,index)
%SUBSREF 資産オブジェクト用のインデックス付きのフィールド名を定義
switch index.type
case '()'
switch index.subs{:}
case 1
b = a.descriptor;
case 2
b = a.date;
case 3
b = a.current_value;
otherwise
error('Index out of range')
end
case '.'
switch index.subs
case 'descriptor'
b = a.descriptor;
case 'date'
b = a.date;
case 'current_value'
b = a.current_value;
otherwise
error('Invalid field name')
end
case '{}'
error('Cell array indexing not supported by asset objects')
end
子subsrefメソッドが親subsrefメソッドを呼び込む方法の例題は、株式subsrefメソッド を参照してください。
| 資産setメソッド | 資産subsasgnメソッド |