Main Content

saveobj

修改对象的保存过程

语法

b = saveobj(a)

说明

如果 a 的类定义 saveobj 方法,则 b = saveobj(a)save 函数调用。save 将返回的值 b 写入 MAT 文件。

定义 loadobj 方法以在加载该对象时采取相应操作。

如果 A 是一个对象数组,MATLAB® 将分别对保存的每个对象调用 saveobj

示例

使用此语法从 saveobj 的子类实现调用超类 saveobj 方法:

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

保存时更新对象:

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

版本历史记录

在 R2006a 之前推出