Options for Class Folders
There are two basic ways to specify classes with respect to folders:
- Creating a single, self-contained class definition file in a folder on the MATLAB path.
- Distributing a class definition to multiple files in an @ folder inside a path folder.
Creating 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 directory on the MATLAB path.
See Methods in Separate Files for more information on using multiple files to define classes.
Distributing the Class Definition to Mulitple 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 @-folder must be inside a folder that is on the MATLAB path. You can define only one class in an @-folder.
A path folder can contain classes defined in both @-folders and single files without an @-folder.
Grouping 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 definitions, package-scoped functions, and other packages. A package folder defines a new name space in which you can reuse class names. Use the package name to refer to classes and functions defined in package folders (for example, packagefld1.ClassNameA(), packagefld2.packageFunction()).
More Information on Class Folders
[note]See Organizing Classes in Folders for more information on class folders and see Scoping Classes with Packages for information on using classes contained in package folders[/note].
[important]See Methods In Separate Files for the syntax used to define methods external to the classdef file.[/important]