Getting Started |
Function Handles
You can create a handle to any MATLAB function and then use that handle as a means of referencing the function. A function handle is typically passed in an argument list to other functions, which can then execute, or evaluate, the function using the handle.
Construct a function handle in MATLAB using the at sign, @
, before the function name. The following example creates a function handle for the sin
function and assigns it to the variable fhandle
.
You can call a function by means of its handle in the same way that you would call the function using its name. The syntax is
The function plot_fhandle
, shown below, receives a function handle and data, generates y-axis data using the function handle, and plots it:
When you call plot_fhandle
with a handle to the sin
function and the argument shown below, the resulting evaluation produces a sine wave plot.
The eval Function | Function Functions |
© 1994-2005 The MathWorks, Inc.