Programming and Data Types    

Constructing a Function Handle

Construct a function handle in MATLAB using the at sign, @, before the function name. The following example creates a function handle for the humps function and assigns it to the variable fhandle.

Pass the handle to another function in the same way you would pass any argument. This example passes the function handle just created to fminbnd, which then minimizes over the interval [0.3, 1].

The fminbnd function evaluates the @humps function handle using feval. A small portion of the fminbnd M-file is shown below. In line 1, the funfcn input parameter receives the function handle, @humps, that was passed in. The feval statement, in line 113, evaluates the handle.


 A Simple Function Handle Maximum Length of a Function Name