Function Precedence Order
This topic explains how MATLAB determines which function to call when multiple functions in the
current scope have the same name. The current scope includes the current file, an optional private
subfolder relative to the currently running function, the current folder, and the MATLAB path.
MATLAB uses this precedence order:
1
Variables
Before assuming that a name matches a function, MATLAB checks for a variable with that name
in the current workspace.
Note If you create a variable with the same name as a function, MATLAB cannot run that
function until you clear the variable from memory.
2
Function or class whose name matches an explicitly imported name
The import function allows functions with compound names (names comprised of several parts
joined by dots) to be called using only the final part of the compound name. When a function
name matches an explicit (non-wildcard) imported function, MATLAB uses the imported
compound name and gives it precedence over all other functions with the same name.
3
Nested functions within the current function
4
Local functions within the current file
5
Function or class whose name matches a wildcard-based imported name
When a function name matches a wildcard-based imported function, MATLAB uses the imported
compound name and gives it precedence over all other functions with the same name, except for
nested and local functions.
6
Private functions
Private functions are functions in a subfolder named private that is immediately below the
folder of the currently running file.
7
Object functions
An object function accepts a particular class of object in its input argument list. When there are
multiple object functions with the same name, MATLAB checks the classes of the input
arguments to determine which function to use.
8
Class constructors in @ folders
MATLAB uses class constructors to create a variety of objects (such as timeseries or
audioplayer), and you can define your own classes using object-oriented programming. For
example, if you create a class folder @polynom and a constructor function @polynom/
polynom.m, the constructor takes precedence over other functions named polynom.m anywhere
on the path.
9
Loaded Simulink
®
models
10 Functions in the current folder
11 Functions elsewhere on the path, in order of appearance
When determining the precedence of functions within the same folder, MATLAB considers the file
type, in this order:
Function Precedence Order
20-37
This topic explains how MATLAB determines which function to call when multiple functions in the
current scope have the same name. The current scope includes the current file, an optional private
subfolder relative to the currently running function, the current folder, and the MATLAB path.
MATLAB uses this precedence order:
1
Variables
Before assuming that a name matches a function, MATLAB checks for a variable with that name
in the current workspace.
Note If you create a variable with the same name as a function, MATLAB cannot run that
function until you clear the variable from memory.
2
Function or class whose name matches an explicitly imported name
The import function allows functions with compound names (names comprised of several parts
joined by dots) to be called using only the final part of the compound name. When a function
name matches an explicit (non-wildcard) imported function, MATLAB uses the imported
compound name and gives it precedence over all other functions with the same name.
3
Nested functions within the current function
4
Local functions within the current file
5
Function or class whose name matches a wildcard-based imported name
When a function name matches a wildcard-based imported function, MATLAB uses the imported
compound name and gives it precedence over all other functions with the same name, except for
nested and local functions.
6
Private functions
Private functions are functions in a subfolder named private that is immediately below the
folder of the currently running file.
7
Object functions
An object function accepts a particular class of object in its input argument list. When there are
multiple object functions with the same name, MATLAB checks the classes of the input
arguments to determine which function to use.
8
Class constructors in @ folders
MATLAB uses class constructors to create a variety of objects (such as timeseries or
audioplayer), and you can define your own classes using object-oriented programming. For
example, if you create a class folder @polynom and a constructor function @polynom/
polynom.m, the constructor takes precedence over other functions named polynom.m anywhere
on the path.
9
Loaded Simulink
®
models
10 Functions in the current folder
11 Functions elsewhere on the path, in order of appearance
When determining the precedence of functions within the same folder, MATLAB considers the file
type, in this order:
Function Precedence Order
20-37
