Order in Path Folder and File File Defines
1 fldr1/Foo.m Class Foo
2 fldr2/Foo.m Function Foo
3 fldr3/@Foo/Foo.m Class Foo
4 fldr4/@Foo/bar.m Method bar
5 fldr5/Foo.m Class Foo
Here is the logic that MATLAB applies to determine which version of Foo to call:
Class fldr1/Foo.m takes precedence over the class fldr3/@Foo because:
- fldr1/Foo.m is before fldr3/@Foo on the path
Class fldr3/@Foo takes precedence over function fldr2/Foo.m because:
- fldr3/@Foo is a class in a class folder
- fldr2/Foo.m is not a class
- Classes in class folders take precedence over functions
Function fldr2/Foo.m takes precedence over class fldr5/Foo.m because:
- fldr2/Foo.m comes before class fldr5/Foo.m on the path
- fldr5/Foo.m is not in a class folder
- Classes that are not defined in class folders obey the path order with respect to
functions.
Class fldr3/@Foo takes precedence over class fldr4/@Foo because:
- The method bar is not recognized as part of the Foo class defined in fldr3/@Foo.
If fldr3/@Foo/Foo.m does not contain a classdef keyword (that is, it is a MATLAB
class prior to Version 7.6), then fldr4/@Foo/bar.m becomes a method of the Foo class
defined in fldr3/@Foo
Previous Behavior of Classes Defined in Class Folders
In MATLAB Versions 5 through 7, class folders do not shadow other class folders having
the same name, but residing in later path folders. Instead, the class uses the combination
6 Defining and Organizing Classes