Programming and Data Types | ![]() ![]() |
A function handle is a MATLAB data type that contains information used in referencing a function. When you create a function handle, MATLAB stores in the handle all the information about the function that it needs to execute, or evaluate, it later on. Typically, a function handle is passed in an argument list to other functions. It is then used in conjunction with feval
to evaluate the function to which the handle belongs.
A MATLAB function handle is more than just a reference to a function. It often represents a collection of function methods, overloaded to handle different argument types. When you create a handle to a function, MATLAB takes a snapshot of all built-in and M-file methods of that name that are on the MATLAB path and in scope at that time, and stores access information for all of those methods in the handle.
When it comes time to evaluate the function handle, MATLAB considers only those functions that were stored within the handle when it was created. Other functions that might now be on the path or in scope are not considered. It is the combination of which functions are in the handle and what arguments the handle is evaluated with that determines which is the actual function that MATLAB dispatches to.
This chapter addresses the following topics:
![]() | Cell Arrays of Structures | Benefits of Using Function Handles | ![]() |