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.

9 Classes and Objects<br />

error('Asset properties: Descriptor, Date, CurrentValue')<br />

end<br />

end<br />

Subclass set methods call the asset set method and require the capability to<br />

return the modified object since <strong>MATLAB</strong> does not support passing arguments<br />

by reference. See “The Stock set Method” on page 9-53 for an example.<br />

The Asset subsref Method<br />

The subsref method provides access to the data contained in an asset object<br />

using one-based numeric indexing and structure field name indexing. The<br />

outer switch statement determines if the index is a numeric or field name<br />

syntax. The inner switch statements map the index to the appropriate value.<br />

<strong>MATLAB</strong> calls subsref whenever you make a subscripted reference to an<br />

object (e.g., A(i), A{i}, orA.fieldname).<br />

function b = subsref(a,index)<br />

%SUBSREF Define field name indexing for asset objects<br />

switch index.type<br />

case '()'<br />

switch index.subs{:}<br />

case 1<br />

b = a.descriptor;<br />

case 2<br />

b = a.date;<br />

case 3<br />

b = a.currentValue;<br />

otherwise<br />

error('Index out of range')<br />

end<br />

case '.'<br />

switch index.subs<br />

case 'descriptor'<br />

b = a.descriptor;<br />

case 'date'<br />

b = a.date;<br />

case 'currentValue'<br />

b = a.currentValue;<br />

9-46

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

Saved successfully!

Ooh no, something went wrong!