functions

Information about a function handle: name, type and file.

Category: Language Fundamentals > Data Types

Syntax

info = functions(fh)

Returns a struct describing the handle fh.

Description

The type field is 'simple' for a plain named function, 'anonymous' for @(x) ... handles, and other values for nested and local functions. Captured variables are what make @(x) a*x remember a; functions is the way to inspect them.

Input arguments

fh
Function handle.

Output arguments

info
Struct with the fields function, type and file. For anonymous functions it also has workspace, a cell holding a struct of the variables captured when the handle was created.

Example

Inspecting a handle

f = functions(@sin)
k = 3;
g = functions(@(a) a + k);
g.type
g.workspace{1}
Output
f = struct with fields:

    function: 'sin'
        type: 'simple'
        file: ''
ans = 'anonymous'
ans = struct with fields:

    k: 3

See also

func2str str2func feval cellfun