To run an individual section inside a script or live script, place the cursor inside the section and use
the
Run Section button (requires R2017b or later for .m files). In live scripts or functions (.mlx
files), you only can run sections that are before the local function definitions.
Restrictions for Local Functions and Variables
Local functions are only visible within the file where they are defined. They are not visible to
functions in other files, and cannot be called from the Command Window.
Local functions in the current file have precedence over functions in other files. That is, when you call
a function within a script, MATLAB checks whether the function is a local function before looking for
the function in other locations. This allows you to create an alternate version of a particular function
while retaining the original in another file.
Scripts create and access variables in the base workspace. Local functions, like all other functions,
have their own workspaces that are separate from the base workspace. Local functions cannot access
variables in the workspace of other functions or in the base workspace, unless you pass them as
arguments.
Access Help for Local Functions
Although you cannot call a local function from the command line or from functions in other files, you
can access its help using the help command. Specify the names of both the script and the local
function, separating them with a > character.
For example:
help mystats>mymean
mymean Local function that calculates mean of array.
See Also
More About
•
“Create Functions in Files” on page 20-2
•
“Function Precedence Order” on page 20-37
•
“Base and Function Workspaces” on page 20-9
Add Functions to Scripts
18-13
Précédent

- 617/1450

Suivant