Documentation

localfunctions

Function handles to all local functions in MATLAB file

Syntax

Description

example

fcns = localfunctions returns a cell array of function handles, fcns, to all local functions in the current file.

You cannot define local functions in the context of the command line, scripts, or anonymous functions, so when you call localfunctions from these contexts, you get an empty cell array. Within the cell array, localfunctions returns the function handles in an undefined order.

Examples

collapse all

Create Handles to Local Functions in File

Create the following function in a file, ellipseVals.m, in your working folder. The function returns a cell array with handles to all the local functions.

function fh = ellipseVals
fh = localfunctions;
end

function f = computeFocus(a,b)
f = sqrt(a^2-b^2);
end

function e = computeEccentricity(a,b)
f = computeFocus(a,b);
e = f/a;
end

function ae = computeArea(a,b)
ae = pi*a*b;
end

At the command prompt, invoke the function to get a cell array of handles to the local functions.

fh = ellipseVals
fh = 

    @computeFocus       
    @computeEccentricity
    @computeArea  

Call a local function using its handle to compute the area of an ellipse. The computeArea function handle is the third element in the cell array.

fh{3}(3,1)
ans =

    9.4248

More About

See Also

Introduced in R2013b

Was this topic helpful?