Information about function handle
returns
information about a function handle. This information includes the
function name, type, and file name.s = functions(fh)
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.
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 =
11Display 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.
s.workspace{1}ans =
y: 7Create 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; end end function y = localFunction(z) y = z + 1; end
Invoke the function.
[hNest,hLocal] = functionsExample(13)
hNest =
@functionsExample/nestFunction
hLocal =
@localFunctionDisplay 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'}
fh — Handle to queryHandle to query, specified as a function handle.
s — Information about function handleInformation 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 |
| Function type. For example |
| Full path to the function with the file extension.
|
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.
You have a modified version of this example. Do you want to open this example with your edits?