Programming Previous page   Next Page

Changing the Portfolio Constructor

The portfolio structure array needs an additional field to accommodate the account number. To create this field, add the line

to @portfolio/portfolio.m in both the zero argument and variable argument sections.

The getAccountNumber Function

In this example, getAccountNumber is a MATLAB function that returns an account number composed of the first three letters of the client name prepended to a series of digits. To illustrate implementation techniques, getAccountNumber is not a portfolio method so it cannot access the portfolio object data directly. Therefore, it is necessary to define a portfolio subsref method that enables access to the name field in a portfolio object's structure.

For this example, getAccountNumber simply generates a random number, which is formatted and concatenated with elements 1 to 3 from the portfolio name field.

Note that the portfolio object is indexed by field name, and then by numerical subscript to extract the first three letters. The subsref method must be written to support this form of subscripted reference.


Previous page  The loadobj Method The Portfolio subsref Method Next page

© 1994-2005 The MathWorks, Inc.