Create a Single, Self-Contained Class Definition File
Create a single, self-contained class definition file in a folder on the MATLAB® path. The
name of the file must match the class (and constructor) name and must have the .m
extension. Define the class entirely in this file. You can put other single-file classes in this
folder.
The following diagram shows an example of this folder organization. pathfolder is a
folder on the MATLAB path.
ClassNameA.m Contains classdef and methods for ClassNameA
pathfolder
ClassNameB.m Contains classdef and methods for ClassNameB
ClassNameC.m Contains classdef and methods for ClassNameC
...
ordinaryFunction.m A function on the path
Distribute the Class Definition to Multiple Files
If you use multiple files to define a class, put all the class-definition files (the file
containing the classdef and all class method files) in a single @ClassName folder. That
class folder must be inside a folder that is on the MATLAB path. You can define only one
class in a class folder.
pathfolder
ClassNameB.m
ClassNameA.m Contains classdef
@ClassNameA
classMethod.m Class method in separate !le
Contains entire class de!nition
A path folder can contain classes defined in both class folders and single files without a
class folder.
Group Classes with Package Folders
The parent folder to a package folder is on the MATLAB path, but the package folder is
not. Package folders (which always begin with a + character) can contain multiple class
Class Files and Folders