Programming |
The Asset subsasgn Method
The subsasgn
method is the assignment equivalent of the subsref
method. This version enables you to change the data contained in an 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 value to the appropriate value in the stock structure.
MATLAB calls subsasgn
whenever you execute an assignment statement (e.g., A(i) = val
, A{i} = val
, or A.fieldname = val
).
function a = subsasgn(a,index,val) % SUBSASGN Define index assignment for asset objects switch index.type case '()' switch index.subs{:} case 1 a.descriptor = val; case 2 a.date = val; case 3 a.currentValue = val; otherwise error('Index out of range') end case '.' switch index.subs case 'descriptor' a.descriptor = val; case 'date' a.date = val; case 'currentValue' a.currentValue = val; otherwise error('Invalid field name') end end
The subsasgn
method enables you to assign values to the asset object data structure using two techniques. For example, suppose you have a child stock object s
. (If you want to run this statement, you first need to create a stock constructor method.)
Within stock class methods, you could change the descriptor
field with either of the following statements
See the The Stock subsasgn Method for an example of how the child subsasgn
method calls the parent subsasgn
method.
The Asset subsref Method | The Asset display Method |
© 1994-2005 The MathWorks, Inc.