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
Create a function handle and display its information.
fh = @cos; s = functions(fh)
s = struct with fields:
function: 'cos'
type: 'simple'
file: 'MATLAB built-in function'
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'}
Input Arguments
Handle to query, specified as a function handle.
Output Arguments
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
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)