Object Save and Load
Customize the object save and load process
MATLAB® provides default behavior for load
and
save
with objects, but you can customize the
process of serializing (saving) and deserializing (loading) objects using
one of two approaches:
Recommended: Inherit from
matlab.mixin.CustomElementSerialization
(since R2024b).
See When to Customize the Serialization Process for more information.
Classes
matlab.mixin.CustomElementSerialization | Customize how objects are serialized and deserialized (Since R2024b) |
matlab.serialization.ElementSerializationContent | Representation of serialized object (Since R2024b) |
matlab.serialization.SerializationContext | Context in which objects are serialized (Since R2024b) |
Topics
Default Behavior for save
and load
with Objects
- Default Save and Load Process for Objects
MATLAB follows some default guidelines to serialize (save) and deserialize (load) objects. - Avoid Property Initialization Order Dependency
Avoid initialization order dependency by defining set methods for dependent properties.
Customize Object Serialization
- When to Customize the Serialization Process
Modify the save and load process for objects. - Maintain Backward and Forward Compatibility Between Class Definitions
Modify the save and load process to provide class version compatibility. - Serialization with Class Hierarchies
Subclasses can callmatlab.mixin.CustomElementSerialization
methods of their superclasses. - Transitioning Serialization and Deserialization Processes to matlab.mixin.CustomElementSerialization
Consider transitioning tomatlab.mixin.CustomElementSerialization
from olderloadobj
andsaveobj
implementations. - Code Patterns for saveobj and loadobj
Use these patterns to implement custom save and load processes usingsaveobj
andloadobj
.