Programming |
The Stock display Method
When you issue the statement (without terminating with a semicolon)
MATLAB looks for a method in the @stock
directory called display
. The display
method for the stock class produces this output.
Descriptor: XYZ Date: 17-Nov-1998 Type: stock Current Value: 2500.00 Number of shares: 100 Share price: 25.00
Here is the stock display
method.
function display(s) % DISPLAY(s) Display a stock object display(s.asset) stg = sprintf('Number of shares: %g\nShare price: %3.2f\n',... s.numShares,s.sharePrice); disp(stg)
First, the parent asset object is passed to the asset display
method to display its fields (MATLAB calls the asset display
method because the input argument is an asset object). The stock object's fields are displayed in a similar way using a formatted text string.
Note that if you did not implement a stock class display
method, MATLAB would call the asset display
method. This would work, but would display only the descriptor, date, type, and current value.
The Stock subsasgn Method | Example -- The Portfolio Container |
© 1994-2005 The MathWorks, Inc.