| MATLAB Function Reference | ![]() |
Method called by save function for user-defined objects
B = saveobj(A)
B = saveobj(A) is called by the MATLAB save function when object A is saved to a MAT-file. This call executes the object's saveobj method, if such a method exists. The returned value B is used by save to populate the MAT-file.
You can define a saveobj method to modify the object before the save operation. For example, you might define a saveobj method that saves related data along with the object.
A subclass object does not inherit the saveobj method of its superclass. saveobj is invoked separately for each object to be saved.
The following example shows a saveobj method that determines if an object has already been assigned an account number from a previous save operation. If not, saveobj calls the object's getAccountNumber method to obtain an account number and assigns it to the AccountNumber property. The value returned by saveobj (b) is saved to the MAT-file.
function b = saveobj(a)
if isempty(a.AccountNumber)
a.AccountNumber = getAccountNumber(a);
end
b = a;
end![]() | saveas | savepath | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |