MATLAB Function Reference    
saveobj

Save an object to a MAT-file

Syntax

Description

B = saveobj(A) is called by the MATLAB save function when object, A, is saved to a .MAT file. This call executes the saveobj method for the object's class, if such a method exists. The return value B is subsequently used by save to populate the .MAT file.

When you issue a save command on an object, MATLAB looks for a method called saveobj in the class directory. You can overload this method to modify the object before the save operation. For example, you could define a saveobj method that saves related data along with the object.

saveobj will be separately invoked for each object to be saved.

saveobj can be overloaded only for user objects. save will not call saveobj for a built-in datatype, such as double, even if @double/saveobj exists.

Examples

The following example shows a saveobj method written for the portfolio class. The method determines if a portfolio object has already been assigned an account number from a previous save operation. If not, saveobj calls getAccountNumber to obtain the number and assigns it to the account_number field. The contents of b is saved to the MAT-file.

See Also

save, loadobj


 saveas save (serial)