Programming and Data Types | ![]() ![]() |
Historical Note - Evaluating Function Names
Evaluating a function by means of a function handle replaces the former MATLAB mechanism of evaluating a function through a string containing the function name. For example, of the following two lines of code that evaluate the humps
function, the second supersedes the first and is considered to be the preferable mechanism to use.
feval('humps', 0.5674); % uses a function name string feval(@humps, 0.5674); % uses a function handle
To support backward compatibility, feval
still accepts a function name string as a first argument and evaluates the function named in the string. However, function handles offer you the additional performance, reliability, and source file control benefits listed in Benefits of Using Function Handles.
![]() | Handling Error Conditions | MATLAB Classes and Objects | ![]() |