Main Content

Function Handles

Variables that allow you to invoke a function indirectly

A function handle is a MATLAB®data type that represents a function. A typical use of function handles is to pass a function to another function. For example, you can use function handles as input arguments to functions that evaluate mathematical expressions over a range of values.

Function handles can represent either named or anonymous functions. To create a function handle, use the@operator. For example, create a handle to an anonymous function that evaluates the expressionx2y2:

f = @(x,y) (x.^2 - y.^2);
For more information, seeCreate Function Handle.

Functions

function_handle Handle to function
feval Evaluate function
func2str Construct character vector from function handle
str2func Construct function handle from character vector
localfunctions Function handles to all local functions inMATLABfile
functions Information about function handle

Topics

Create Function Handle

使用一个函数处理创建一个协会a named function or an anonymous function. Then, you can indirectly call the representative function.

Pass Function to Another Function

You can use function handles as input arguments to functions that evaluate mathematical expressions over a range of values, such asintegralandfzero.

Parameterizing Functions

This topic explains how to store or access extra parameters for mathematical functions that you pass to functions such asfzero,ode45, orintegral.

Call Local Functions Using Function Handles

If a function returns handles to local functions, you can call the local functions outside of the main function. This approach allows you to have multiple, callable functions in a single file.

Compare Function Handles

The result of comparing equality of function handles depends on what the handle represents and when you created it.