23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9 Classes and Objects<br />

Examples of Constructor Methods<br />

See the following sections for examples of constructor methods:<br />

• “The Polynom Constructor Method” on page 9-27<br />

• “The Asset Constructor Method” on page 9-43<br />

• “The Stock Constructor Method” on page 9-50<br />

• “The Portfolio Constructor Method” on page 9-59<br />

Identifying Objects Outside the Class Directory<br />

The class and isa functions used in constructor methods can also be used<br />

outside of the class directory. The expression<br />

isa(a,'classname');<br />

checks whether a is an object of the specified class. For example, if p is a<br />

polynom object, each of the following expressions is true.<br />

isa(pi,'double');<br />

isa('hello','char');<br />

isa(p,'polynom');<br />

Outside of the class directory, the class function takes only one argument (it<br />

is only within the constructor that class canhavemorethanoneargument).<br />

The expression<br />

class(a)<br />

returns a string containing the class name of a. For example,<br />

class(pi),<br />

class('hello'),<br />

class(p)<br />

return<br />

'double',<br />

'char',<br />

'polynom'<br />

9-12

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

Saved successfully!

Ooh no, something went wrong!