Object creation.
object = class(strct, 'classname') object = class(strct, 'classname', parent1, ...) str = class(object)
class(strct,'classname') makes an object of the specified class with the data of structure strct. Object fields can be accessed only from methods of that class, i.e. functions whose name is classname::methodname. Objects must be created by the class constructor classname::classname.
class(strct,'classname',parent1,...) makes an object of the specified class which inherits fields and methods from one or several other object(s) parent1, ... Parent objects are inserted as additional fields in the object, with the same name as the class. Fields of parent objects cannot be directly accessed by the new object's methods, only by the parent's methods.
class(object) gives the class of object as a string. The table below gives the name of native types.
Class | Native type |
---|---|
double | real, complex, or logical scalar or array |
char | character or character array |
list | list or structure |
inline | inline function |
funref | function reference |
o1 = class(struct('fld1', 1, 'fld2', rand(4)), 'c1'); o2 = class(struct('fld3', 'abc'), 'c2', o1); class(o2) c2
Test for an object of a given class.
b = isa(object,'classname')
isa(object,'classname') returns true of object is an object of class class, directly or by inheritance.
isa(pi,'double') true
Test for an object.
b = isobject(a)
object(a) returns true if a is an object created with class.
List of methods for a class.
methods classname list = methods('classname')
methods classname displays the list of methods defined for class classname. Inherited methods and private methods are ignored. With an output argument, methods gives produces a list of strings.