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 />

Converter Methods<br />

A converter method is a class method that has the same name as another<br />

class, such as char or double. Converter methods accept an object of one class<br />

as input and return an object of another class. Converters enable you to<br />

• Use methods defined for another class<br />

• Ensure that expressions involving objects of mixed class types execute<br />

properly<br />

Aconverterfunction call is of the form<br />

b = classname(a)<br />

where a is an object of a class other than classname. In this case, <strong>MATLAB</strong><br />

looks for a method called classname in the class directory for object a. Ifthe<br />

inputobjectisalready of type classname, then <strong>MATLAB</strong> calls the constructor,<br />

which just returns the input argument.<br />

Examples of Converter Methods<br />

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

• “The Polynom to Double Converter” on page 9-28<br />

• “The Polynom to CharConverter”onpage9-29<br />

9-22

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

Saved successfully!

Ooh no, something went wrong!