Save and Load System Object
This example shows how to load and save a System object.
Save System Object and Child Object
Define a saveObjectImpl method to specify that more than just public properties
should be saved when the user saves a System object. Within this method, use the default
[email protected] to save public properties to the struct, s. Use the
saveObject method to save child objects. Save protected and dependent properties, and
finally, if the object has been called and not released, save the object state.
methods (Access = protected)
function s = saveObjectImpl(obj)
s = [email protected](obj);
s.child = matlab.System.saveObject(obj.child);
s.protectedprop = obj.protectedprop;
s.pdependentprop = obj.pdependentprop;
if isLocked(obj)
s.state = obj.state;
end
end
end
Load System Object and Child Object
Define a loadObjectImpl method to load a previously saved System object. Within this
method, use the loadObject to load the child System object, load protected and private
properties, load the state if the object was called and not released, and use
loadObjectImpl from the base class to load public properties.
methods (Access = protected)
function loadObjectImpl(obj,s,isInUse)
obj.child = matlab.System.loadObject(s.child);
obj.protectedprop = s.protectedprop;
obj.pdependentprop = s.pdependentprop;
if isInUse
obj.state = s.state;
end
34 System object Usage and Authoring