localfunctions

Returns handles to the local functions defined in the current file.

Category: Language Fundamentals > Data Types

Syntax

c = localfunctions

Returns a cell array of function handles, one per local function.

Description

Local functions can be called only from inside their own file, so the handles from localfunctions are the way to hand them to code elsewhere, for example to run a set of test functions in a loop. The call must be made from inside the file whose functions are wanted.

Output arguments

c
Column cell array of function handles. It is empty when the file has no local functions.

Example

Listing local functions

c = localfunctions;
numel(c)
for k = 1:numel(c)
  disp(c{k}())
end

function r = first()
  r = 'one';
end

function r = second()
  r = 'two';
end
Output
ans = 2
one
two

See also

func2str str2func feval