Programming Previous page   Next Page

Saving and Loading Objects

You can use the MATLAB save and load commands to save and retrieve user-defined objects to and from .mat files, just like any other variables.

When you load objects, MATLAB calls the object's class constructor to register the object in the workspace. The constructor function for the object class you are loading must be able to be called with no input arguments and return a default object. See Guidelines for Writing a Constructor for more information.

Modifying Objects During Save or Load

When you issue a save or load command on objects, MATLAB looks for class methods called saveobj and loadobj in the class directory. You can overload these methods to modify the object before the save or load operation. For example, you could define a saveobj method that saves related data along with the object or you could write a loadobj method that updates objects to a newer version when this type of object is loaded into the MATLAB workspace.


Previous page  Creating a Portfolio Example -- Defining saveobj and loadobj for Portfolio Next page

© 1994-2005 The MathWorks, Inc.