Describe MATLAB class
Instances of the meta.class
class contain information about MATLAB® classes. The read/write properties of the meta.class
class correspond to class attributes and are set only from within class definitions on
the classdef
line. You can query the read–only properties of the
meta.class
object to obtain information that is specified
syntactically by the class (for example, to obtain the name of the class).
You cannot instantiate a meta.class
object
directly. You can construct a meta.class
object
from an instance of a class or using the class name:
metaclass
— returns a meta.class
object
representing the object passed as an argument.
?
ClassName
—
returns a meta.class
object representing the named
class.
fromName
— static method
returns a meta.class
object representing the named
class.
For example, the metaclass
function returns
the meta.class
object representing MyClass
.
ob = MyClass; obmeta = metaclass(ob); obmeta.Name
ans = MyClass
You can use the class name to obtain the meta.class
object:
obmeta = ?MyClass;
You can also use the fromName
static method:
obmeta = meta.class.fromName('MyClass');
Property | Purpose |
---|---|
| If For more information, see Abstract Classes. |
ConstructOnLoad attribute, default = false | If |
ContainingPackage read only | A |
Description read only | Currently not used. |
DetailedDescription read only | Currently not used. |
Enumeration attribute, default = false | If |
EventList read only | An array of See Events. |
Events read onlyUse | A cell array of |
EnumerationMemberList | An array of See Enumerations for more information on enumeration classes. |
EnumeratedValues read only Use | A cell array of See Enumerations for more information on enumeration classes. |
Hidden attribute, default = false | If set to true , the class does not appear
in the output of MATLAB commands or tools that display class
names. |
InferiorClasses attribute, default = {} | A cell array of See Class Precedence |
MethodList read only | An array of |
Methods read only Use | A cell array of |
Name read only | Name of the class associated with this meta.class object
(char array) |
PropertyList read only | An array of See Properties. |
Properties read only Use | A cell array of See Properties. |
| If the class is not |
Sealed attribute, default = false | If |
SuperClassList read only | An array of |
SuperClasses read only Use | A cell array of |
Method | Purpose |
---|---|
fromName | Returns the meta.class object associated
with the specified class name. |
tf = eq(Cls) | Equality function (a == b ). Use to test
if two variables refer to equal classes (classes that contain exactly
the same list of elements). |
tf = ne(Cls) | Not equal function (a ~= b ). Use to test
if two variables refer to different meta–classes. |
tf = lt(ClsA,ClsB) | Less than function (ClsA < ClsB ). Use
to determine if ClsA is a strict subclass of ClsB (i.e.,
a strict subclass means ClsX < ClsX is false ). |
tf = le(ClsA,ClsB) | Less than or equal to function (ClsA <= ClsB ).
Use to determine if ClsA is a subclass of ClsB . |
tf = gt(ClsA,ClsB) | Greater than function (ClsA > ClsB ).
Use to determine if ClsA is a strict superclass
of ClsB (i.e., a strict superclass means ClsX
> ClsX is false ). |
tf = ge(ClsA,ClsB) | Greater than or equal to function (ClsA >= ClsB ).
Use to determine if ClsA is a superclass of ClsB . |
Event | Purpose |
---|---|
| If the class is a handle class, this event occurs every time a new instance of this handle class is created, including new instances of any subclasses. The event occurs immediately after all constructor functions finish executing. |
| If the class is a handle class, this event occurs every time an instance of this handle class is destroyed, including all subclasses. The event occurs immediately before any destructor functions execute. |
Find property attributes using the handle
class findobj
method
and the audioplayer
meta.class
object.
Determine if a class defines the property named SampleRate
and
does it have public set access.
mc = ?audioplayer; mp = findobj(mc.PropertyList,'Name','SampleRate'); strcmp(mp.SetAccess,'public') ...
fromName
| meta.event
| meta.method
| meta.package
| meta.property