MATLAB Documentation for OOP
(For reference by students)


 

CLASS
Definition Creates an object or return object class.

It must be invoked within a constructor method,
in a file named <class_name>.m in a directory named @<class_name>.
Further, 'class_name' must be the second argument to CLASS.

O = CLASS(S,'class_name') creates an object of class 'class_name'
from the structure S.

O = CLASS(S,'class_name',PARENT1,PARENT2,...) also inherits the
methods and fields of the parent objects PARENT1, PARENT2, ...

O = CLASS(struct([]),'class_name',PARENT1,PARENT2,...), specifying
an empty structure S, creates an object that inherits from one or
more parent classes, but which does not have any additional fields
not inherited from the parents.
 

Example
function acct = BankAccount(data)
if nargin == 0
   acct.balance = 0;
   acct = class(acct,'BankAccount');
elseif isa(data, 'BankAccount')
   acct = data;
else
   acct.balance = data;
   acct = class(acct,'BankAccount'); ----> creates a object of class BankAccount
end
 
 


Got comments\feedback\suggestions\complaints\anything whatsoever? Shoot the webmaster an email!

Website created & maintained by Shardul Bhatia and Wen Eu Cheah