Programming and Data Types | ![]() ![]() |
The saveobj Method
MATLAB looks for the portfolio saveobj
method whenever the save
command is passed a portfolio object. If @portfolio/saveobj
exists, MATLAB passes the portfolio object to saveobj
, which must then return the modified object as an output argument. The following implementation of saveobj
determines if the 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.
function b = saveobj(a) if isempty(a.account_number) a.account_number = getAccountNumber(a); end b = a;
![]() | Example -- Defining saveobj and loadobj for Portfolio | The loadobj Method | ![]() |