Documentation

classdef

Class definition keywords

Syntax

classdefClassName... end

Description

classdefClassNamebegins the class definition and anendkeyword terminates theclassdefblock. Only blank lines and comments can precedeclassdef. Enter a class definition in a file having the same name as the class, with a filename extension of.m.

Class definition files can be in folders on the MATLAB®path or in class folders whose parent folder is on the MATLAB path. Class folder names begin with the'@'character followed by the class name (for example,@MyClass). For more information on class folders, seeClass Files and Folders.

For more information on classes, seeClassdef BlockandClass Definition.

propertiesbegins a property definition block, anendkeyword terminates thepropertiesblock. Class definitions can contain multiple property definition blocks, each specifying different attribute settings that apply to the properties in that particular block.

For more information on properties, seeProperty Syntax.

Note

Properties cannot have the same name as the class.

methods开始德方法finition block, anendkeyword terminates themethodsblock. This block contains functions that implement class methods. Class definitions can contain multiple method blocks, each specifying different attribute settings that apply to the methods in that particular block. It is possible to define method functions in separate files.

For more information on methods, seeMethods in Class Design.

eventsbegins an events definition block, anendkeyword terminates theeventsblock. This block contains event names defined by the class. Class definitions can contain multiple event blocks, each specifying different attribute settings that apply to the events in that particular block.

For more information on events, seeEvents and Listeners Syntax.

enumerationbegins an enumeration definition block, anendkeyword terminates theenumerationblock.

For more information on enumerations, seeEnumerations.

properties,methods,events, andenumerationare also the names of MATLAB functions used to query the respective class members for a given object or class name.

Examples

Use these keywords to define classes.

classdef(Attributes)ClassNameproperties(Attributes)PropertyNameendmethods(Attributes)functionobj =methodName(obj,arg2,...) ...endendevents(Attributes)EventNameendenumerationEnumNameendend

Introduced in R2008a

Was this topic helpful?