Programming Previous page   Next Page

The Stock subsasgn Method

The subsasgn method enables you to change the data contained in a stock object using numeric indexing and structure field name indexing. MATLAB calls subsasgn whenever you execute an assignment statement
(e.g., A(i) = val, A{i} = val, or A.fieldname = val).

The outer switch statement determines if the index is a numeric or field name syntax.

The fieldcount asset method determines how many fields there are in the asset structure and the if statement calls the asset subsasgn method for indices 1 to fieldcount. See The Asset fieldcount Method and The Asset subsasgn Method for a description of these methods.

Numeric indices greater than the number returned by fieldcount are handled by the inner switch statement, which maps the index value to the appropriate field in the stock structure.

Field-name indexing assumes field names other than numShares and sharePrice are asset fields, which eliminates the need for knowledge of asset fields by child methods. The asset subsasgn method performs field-name error checking.

The subsasgn method enables you to assign values to stock object data structure using two techniques. For example, suppose you have a stock object

You could change the descriptor field with either of the following statements

or

See the subsasgn help entry for general information on assignment statements in MATLAB.


Previous page  The Stock subsref Method The Stock display Method Next page

© 1994-2005 The MathWorks, Inc.