Programming |
The Asset subsref Method
The subsref
method provides access to the data contained in an asset object using one-based numeric indexing and structure field name indexing. The outer switch
statement determines if the index is a numeric or field name syntax. The inner switch
statements map the index to the appropriate value.
MATLAB calls subsref
whenever you make a subscripted reference to an object (e.g., A(i)
, A{i}
, or A.fieldname
).
function b = subsref(a,index) %SUBSREF Define field name indexing for asset objects switch index.type case '()' switch index.subs{:} case 1 b = a.descriptor; case 2 b = a.date; case 3 b = a.currentValue; otherwise error('Index out of range') end case '.' switch index.subs case 'descriptor' b = a.descriptor; case 'date' b = a.date; case 'currentValue' b = a.currentValue; otherwise error('Invalid field name') end case '{}' error('Cell array indexing not supported by asset objects') end
See the The Stock subsref Method for an example of how the child subsref
method calls the parent subsref
method.
The Asset set Method | The Asset subsasgn Method |
© 1994-2005 The MathWorks, Inc.