loadobj
Customize load process for objects
Syntax
Description
Note
The matlab.mixin.CustomElementSerialization class is recommended over
loadobj and saveobj because the mixin
provides greater control over how objects are serialized and deserialized, including
the ability to add, delete, and rename properties. (since R2024b)
deserializes an object represented by b = loadobj(a)a. Define a
loadobj method when objects of a class require special processing
when loaded from MAT files. If you define a saveobj method, then define a loadobj method to restore
the object to the desired state. If the class of the object defines a
loadobj method, load automatically calls it.
Examples
Input Arguments
Output Arguments
Tips
Define
loadobjas a static method.Implement your
loadobjmethod to work with scalar objects or structures. When you deserialize an object array,loadcallsloadobjon each element of the saved array.When a new version of a class removes, renames, or changes the validation for a property,
loadcan generate an error when attempting to set the altered or deleted property. If the class defines aloadobjmethod, MATLAB returns the saved values to theloadobjmethod in astruct. If the saved object derives from multiple superclasses that have private properties with same name, thestructcontains only the property value of the most direct superclass.When loading a subclass object,
loadcalls only the subclassloadobjmethod. If a superclass defines aloadobjmethod, the subclass inherits this method. However, the inherited method might not perform the necessary operations to load the subclass object. Consider overriding superclassloadobjmethods if needed for your application. You can also call a superclassloadobjfrom a subclassloadobj.
Version History
Introduced before R2006a