functions
Information about function handle
Syntax
Description
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.
Examples
Display Information About Named Function Handle
Create a function handle and display its information.
fh = @cos; s = functions(fh)
s = struct with fields:
function: 'cos'
type: 'simple'
file: ''
Display Information About Anonymous Function Handle
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 = 11
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
.
s.workspace{1}
ans = y: 7
Display Information About Nested and Local Function Handle
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; end end function y = localFunction(z) y = z + 1; end
Invoke the function.
[hNest,hLocal] = functionsExample(13)
hNest = @functionsExample/nestFunction hLocal = @localFunction
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
fh
— Handle to query
function handle
Handle to query, specified as a function handle.
Output Arguments
s
— Information about function handle
structure
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 |
| 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.
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)