Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

classdef - Class definition keywords

Syntax

classdef classname
   properties
      PropName
   end
   methods
      methodName
   end
   events
      EventName
   end
end

Description

classdef classname begins the class definition, an end keyword terminates the classdef block. Only blank lines and comments can precede classdef. 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 directories on the MATLAB path or in @ directories whose parent directory is on the MATLAB path. See Class Folders for more information. See The Classdef Block and Defining Classes — Syntax for more information on classes.

properties begins a property definition block, an end key word terminates the properties block. Class definitions can contain multiple property definition blocks, each specifying different attribute settings that apply to the properties in that particular block. See Defining Properties for more information.

methods begins a methods definition block, an end key word terminates the methods block. 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. See Class Methods for more information.

events begins an events definition block, an end key word terminates the events block. 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. See Defining Events and Listeners — Syntax and Techniques for more information.

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

To see the attributes of all class components in a popup window, click this link: Attribute Tables

Examples

Use these keywords to define classes.

classdef class_name
   properties
      PropertyName
   end 
   methods
      function obj = methodName(obj,arg2,...)
         ...
      end
   end
   events 
      EventName
   end
end

See Also

Tutorials

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS