Class Definitions in Path Folders
Suppose that you define two versions of a class named Foo in two folders, fldA and
fldB, but do not use a class folder.
fldA/+FooPkg/Foo.m
fldB/+FooPkg/Foo.m
Add folder fldA to the top of the path.
addpath fldA
Create an instance of class FooPkg.Foo. MATLAB uses fldA/+FooPkg/@Foo/Foo.m as
the class definition.
a = FooPkg.Foo;
Change the current folder to fldB.
cd fldB
The current folder is effectively the top of the path. However, MATLAB does not identify
fldB/+FooPkg/Foo.m as the definition for class FooPkg.Foo. MATLAB continues to use
the original class definition until you clear the class.
To use the definition of FooPkg.Foo in foldB, clear FooPkg.Foo.
clear FooPkg.Foo
MATLAB automatically updates the existing objects to conform to the class definition in
fldB. In most cases, clearing instance variables is unnecessary.
See Also
More About
- “Packages Create Namespaces” on page 6-25
- “Automatic Updates for Modified Classes” on page 5-51
6 Defining and Organizing Classes