MATLAB Function Reference Previous page   Next Page

User-defined extension of load function for user objects



b = loadobj(a) extends the load function for user objects. When an object is loaded from a MAT-file, the load function calls the loadobj method for the object's class if it is defined. The loadobj method must have the calling sequence shown; the input argument a is the object as loaded from the MAT-file, and the output argument b is the object that the load function will load into the workspace.

These steps describe how an object is loaded from a MAT-file into the workspace:

  1. The load function detects the object a in the MAT-file.
  2. The load function looks in the current workspace for an object of the same class as the object a. If there isn't an object of the same class in the workspace, load calls the default constructor, registering an object of that class in the workspace. The default constructor is the constructor function called with no input arguments.
  3. The load function checks to see if the structure of the object a matches the structure of the object registered in the workspace. If the objects match, a is loaded. If the objects don't match, load converts a to a structure variable.
  4. The load function calls the loadobj method for the object's class if it is defined. load passes the object a to the loadobj method as an input argument. Note that the format of the object a is dependent on the results of step 3 (object or structure). The output argument of loadobj, b, is loaded into the workspace in place of the object a.


loadobj can be overloaded only for user objects. load will not call loadobj for built-in data types (such as double).

loadobj is invoked separately for each object in the MAT-file. The load function recursively descends cell arrays and structures, applying the loadobj method to each object encountered.

A child object does not inherit the loadobj method of its parent class. To implement loadobj for any class, including a class that inherits from a parent, you must define a loadobj method within that class directory.

See Also

load, save, saveobj

Previous page  load log Next page

© 1994-2005 The MathWorks, Inc.