Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

The Save and Load Process

The Default Save and Load Process

Use save and load to store objects:

save filename object
load filename object

What Information Is Saved

Saving objects in MAT-files saves:

See Specifying Property Attributes for a description of property attributes.

Loading Property Data

When loading objects from MAT-files the load function:

It is possible for a default value to cause an error in a property set method (for example, the class definition might have changed). When an error occurs while an object is being loaded from a file, MATLAB returns the saved values in a struct. The field names correspond to the property names.

saveobj and loadobj

The save and load functions call your class's saveobj and loadobj methods, respectively, if your class defines these methods. You use these methods to customize the save and load process.

When you issue a save command, MATLAB first calls your saveobj method and passes the output of saveobj to save. Similarly, when you call load, MATLAB passes the result of loading what you saved to loadobj. loadobj must then return a properly constructed object. Therefore, you must design saveobj and loadobj to work together.

When to Modify Object Saving and Loading

The following sections describe when and how to modify the process MATLAB uses to save and load objects. You modify this process by implementing saveobj and loadobj methods for your class.

Why Implement saveobj and loadobj

The primary reason for implementing saveobj and loadobj methods is to support backward and forward compatibility of classes. For example, you might have cases where:

Information to Consider

If you decide to modify the default save and load process, keep the following points in mind:

See Tips for Saving and Loading for guidelines on saving and loading objects.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS