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 or complex double scalar or array |
single | real or complex single scalar or array |
int8/16/32/64 | 8/16/32/64-bit signed integer scalar or array |
uint8/16/32/64 | 8/16/32/64-bit unsigned integer scalar or array |
logical | logical scalar or array |
char | character or character array |
list | list |
cell | cell array |
struct | scalar structure |
structarray | structure array |
inline | inline function |
funref | function reference |
null | null value |
o1 = class({fld1=1, fld2=rand(4)}, 'c1'); o2 = class({fld3='abc'}, 'c2', o1); class(o2) c2
struct, inferiorto, superiorto, isa, isobject, methods
Set class precedence.
inferiorto('class1', ...)
Called in a constructor, inferiorto('class1',...) specifies that the class has a lower precedence than classes whose names are given as input arguments. Precedence is used when a function has object arguments of different classes: the method defined for the class with the highest precedence is called.
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. In addition to the class names given by class, the following classes are supported:
Class | Native type |
---|---|
cell | list or cell array |
numeric | double, single or integer scalar or array |
float | double or single scalar or array |
integer | integer scalar or array |
isa(pi,'double') true
Test for a null value.
b = isnull(a)
isnull(a) returns true if a is the null value created with null, or false for any value of any other type.
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.
Null value.
obj = null
null gives the only value of the null data type. It stands for the lack of any value. Null values can be tested with isnull or with equality or inequality operators == and ~=.
With an input argument, null(A) gives the null space of matrix A.
n = null n = null isnull(n) true n == null true n ~= null false class(n) null
Get list of superclasses.
list = superclasses(obj)
superclasses(obj) gives the list of the names of parent classes (superclasses) of the object obj. Parent classes are specified as additional arguments to class when the object is constructed.
use lti; G = tf(1, [1, 2]); class(G) tf superclasses(G) {'lti'} isa(G, 'lti') true