Skip to Main Content Skip to Search
Product Documentation

saveobj - Modify save process for object

Syntax

b = saveobj(a)

Description

b = saveobj(a) is called by the save function if the class of a defines a saveobj method. save writes the returned value, b, to the MAT-file.

Define a loadobj method to take the appropriate action when loading the object.

If A is an array of objects, MATLAB invokes saveobj separately for each object saved.

Examples

Call the superclass saveobj method from the subclass implementation of saveobj with the following syntax:

classdef mySub < super
   methods
      function sobj = saveobj(obj)
         % Call superclass saveobj method
         sobj = saveobj@super(obj); 
         % Perform subclass save operations
         ...
      end
   ...
   end
...
end

See Saving and Loading Objects from Class Hierarchies.

 

Update object when saved:

function b = saveobj(a)
   % If the object does not have an account number,
   % call method to add account number to AccountNumber property
   if isempty(a.AccountNumber) 
      a.AccountNumber = getAccountNumber(a);
   end
   b = a;
end

See Example — Maintaining Class Compatibility.

See Also

load | loadobj | save

Tutorials

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS