23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example — Assets and Asset Subclasses<br />

function val = get(a, propName)<br />

% GET Get asset properties from the specified object<br />

% and return the value<br />

switch propName<br />

case 'Descriptor'<br />

val = a.descriptor;<br />

case 'Date'<br />

val = a.date;<br />

case 'CurrentValue'<br />

val = a.currentValue;<br />

otherwise<br />

error([propName,' Is not a valid asset property'])<br />

end<br />

This function accepts an object and a property name and uses a switch<br />

statement to determine which field to access. This method is called by the<br />

subclass get methods when accessing the data in the inherited properties.<br />

See“TheStockgetMethod”onpage9-52foranexample.<br />

The Asset set Method<br />

The asset class set method is called by subclass set methods. This method<br />

accepts an asset object and variable length argument list of property<br />

name/property value pairs and returns the modified object.<br />

function a = set(a,varargin)<br />

% SET Set asset properties and return the updated object<br />

propertyArgIn = varargin;<br />

while length(propertyArgIn) >= 2,<br />

prop = propertyArgIn{1};<br />

val = propertyArgIn{2};<br />

propertyArgIn = propertyArgIn(3:end);<br />

switch prop<br />

case 'Descriptor'<br />

a.descriptor = val;<br />

case 'Date'<br />

a.date = val;<br />

case 'CurrentValue'<br />

a.currentValue = val;<br />

otherwise<br />

9-45

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!