Programming and Data Types | ![]() ![]() |
Evaluating a Function Through Its Handle
Execute the target function of a function handle using the MATLAB feval
command. The syntax for using this command with a function handle is
This acts similarly to a direct call to the function represented by fhandle
, passing arguments arg1
through argn
. The principal differences are:
Note
The feval command does not operate on nonscalar function handles. Passing a nonscalar function handle to feval results in an error.
|
Function Evaluation and Overloading
To understand the relationship between function handles and overloading, it is helpful to review, briefly, the nature of MATLAB function calls. Because of overloading, it is useful to think of a single MATLAB function as comprising a number of code sources (for example, built-in code, M-files). When you call a MATLAB function without feval
, the choice of which source is called depends upon two factors:
MATLAB evaluates function handles in a similar manner. In most cases, a function handle represents a collection of methods that overload the function. When you evaluate a function handle using feval
, the choice of the particular method called depends on:
feval
command
![]() | Constructing a Function Handle | Examples of Function Handle Evaluation | ![]() |