Skip to content

saveobj

miscellaneous · scripts/miscellaneous/saveobj.m

: b = saveobj (a)

Class method run on an object just before save writes it.

A class that defines saveobj gets the chance to replace the object a with the version b that should actually go to the file: typically a copy with transient fields dropped, or with derived fields filled in so that the saved form is complete. Such a class normally also defines loadobj to undo the transformation. A minimal method that strips a cache field:

function b = saveobj (a)
  b = a;
  b.cache = [];
endfunction