Quantcast

Documentation Center

  • Trial Software
  • Product Updates

functions

Information about function handle

Syntax

S = functions(funhandle)

Description

S = functions(funhandle) returns, in MATLAB® structure S, the function name, type, filename, and other information for the function handle stored in the variable funhandle.

functions does not operate on nonscalar function handles. Passing a nonscalar function handle to functions results in an error.

    Caution   The functions function is provided for querying and debugging purposes. Because its behavior may change in subsequent releases, you should not rely upon it for programming purposes.

This table lists the standard fields of the return structure.

Field Name

Field Description

function

Function name

type

Function type (e.g., simple, overloaded)

file

The file to be executed when the function handle is evaluated with a nonoverloaded data type

Examples

Example 1

To obtain information on a function handle for the poly function, type

f = functions(@poly)
f = 
    function: 'poly'
        type: 'simple'
        file:  '$matlabroot\toolbox\matlab\polyfun\poly.m'

(The term $matlabroot used in this example stands for the file specification of the directory in which MATLAB software is installed for your system. Your output will display this file specification.)

Access individual fields of the returned structure using dot selection notation:

f.type
ans = 
   simple

Example 2

The function get_handles returns function handles for a local function and private function in output arguments l and p respectively:

function [l, p] = get_handles
l = @mylocfun;
p = @myprivatefun;
%
function mylocfun
disp 'Executing local function mylocfun'

Call get_handles to obtain the two function handles, and then pass each to the functions function. MATLAB returns information in a structure having the fields function, type, file, and parentage. The file field contains the file specification for the local or private function:

[floc fprv] = get_handles;

functions(floc)
ans = 
     function: 'mylocfun'
         type: 'scopedfunction'
         file: 'c:\matlab\get_handles.m'
    parentage: {'mylocfun'  'get_handles'}

functions(fprv)
ans = 
     function: 'myprivatefun'
         type: 'scopedfunction'
         file: 'c:\matlab\private\myprivatefun.m'
    parentage: {'myprivatefun'}

Example 3

In this example, the function get_handles_nested.m contains a nested function nestfun. This function has a single output which is a function handle to the nested function:

function handle = get_handles_nested(A)
nestfun(A);

   function y = nestfun(x)
   y = x + 1;
   end

handle = @nestfun;
end

Call this function to get the handle to the nested function. Use this handle as the input to functions to return the information shown here. Note that the function field of the return structure contains the names of the nested function and the function in which it is nested in the format. Also note that functions returns a workspace field containing the variables that are in context at the time you call this function by its handle:

fh = get_handles_nested(5);

fhinfo = functions(fh)
fhinfo = 
     function: 'get_handles_nested/nestfun'
         type: 'nested'
         file: 'c:\matlab\get_handles_nested.m'
    workspace: [1x1 struct]

fhinfo.workspace
ans = 
    handle: @get_handles_nested/nestfun
         A: 5

See Also

| |

Was this topic helpful?