This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Information about function handle




s = functions(fh) returns information about a function handle. This information includes the function name, type, and file name.

Use the functions function for querying and debugging purposes only.

    Note:   Do not use functions programmatically because its behavior could change in subsequent MATLAB® releases.


collapse all

Create a function handle and display its information.

fh = @cos;
s = functions(fh)
s = 

  struct with fields:

    function: 'cos'
        type: 'simple'
        file: ''

Create a function handle to an anonymous function. Display its information and values of required variables.

Create a handle to the function x2 + y, and invoke the function using the handle.

y = 7;
fh = @(x)x.^2+y;
z = fh(2)
z =


Display information about the function handle.

s = functions(fh)
s = 

            function: '@(x)x.^2+y'
                type: 'anonymous'
                file: ''
           workspace: {[1x1 struct]}
    within_file_path: '__base_function'

The function handle contains the required value of y.

ans = 

    y: 7

Create a function that returns handles to local and nested functions. Display their information.

Create the following function in a file, functionsExample.m, in your working folder. The function returns handles to a nested and local function.

function [hNest,hLocal] = functionsExample(v)

hNest = @nestFunction;
hLocal = @localFunction;

    function y = nestFunction(x)
        y = x + v;


function y = localFunction(z)
y = z + 1;

Invoke the function.

[hNest,hLocal] = functionsExample(13)
hNest = 


hLocal = 


Display information about the handle to the nested function.

s1 = functions(hNest)
s1 = 

     function: 'functionsExample/nestFunction'
         type: 'nested'
         file: 'C:\work\functionsExample.m'
    workspace: {[1x1 struct]}

Display information about the handle to the local function.

s2 = functions(hLocal)
s2 = 

     function: 'localFunction'
         type: 'scopedfunction'
         file: 'C:\work\functionsExample.m'
    parentage: {'localFunction'  'functionsExample'}

Input Arguments

collapse all

Handle to query, specified as a function handle.

Output Arguments

collapse all

Information about a function handle, returned as a structure. The structure contains the following fields.

Field Name

Field Description


Function name. If the function associated with the handle is a nested function, the function name takes the form main_function/nested_function.


Function type. For example 'simple', 'nested', 'scopedfunction', or 'anonymous'.


Full path to the function with the file extension.

  • If the function is a local or nested function, then file is the full path to the main function.

  • If the function is built-in MATLAB function or an anonymous function, then file is an empty character array ('').

  • If you load a saved function handle, then file is an empty character array ('').

The structure has additional fields depending on the type of function associated with the handle. For example, a local function has a parentage field, and an anonymous function has a workspace field. Use the information in s for querying and debugging purposes only.

See Also


Introduced before R2006a

Was this topic helpful?