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

Saving and Loading Objects<br />

You can use the <strong>MATLAB</strong> save and load commands to save and retrieve<br />

user-defined objects to and from .mat files, just like any other variables.<br />

When you load objects, <strong>MATLAB</strong> calls the object’s class constructor to register<br />

theobjectintheworkspace.Theconstructor function for the object class you<br />

are loading must be able to be called with no input arguments and return a<br />

default object. See “Guidelines for Writing a Constructor” on page 9-10 for<br />

more information.<br />

Modifying Objects During Save or Load<br />

When you issue a save or load command on objects, <strong>MATLAB</strong> looks for class<br />

methods called saveobj and loadobj in the class directory. You can overload<br />

these methods to modify the object before the save or load operation. For<br />

example, you could define a saveobj method that saves related data along<br />

with the object or you could write a loadobj method that updates objects to a<br />

newer version when this type of object is loaded into the <strong>MATLAB</strong> workspace.<br />

9-64

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

Saved successfully!

Ooh no, something went wrong!