Skip to Main Content Skip to Search
Product Documentation

feval - Evaluate function

Syntax

[y1, y2, ...] = feval(fhandle, x1, ..., xn)
[y1, y2, ...] = feval(fname, x1, ..., xn)

Description

[y1, y2, ...] = feval(fhandle, x1, ..., xn) evaluates the function handle, fhandle, using arguments x1 through xn. If the function handle is bound to more than one built-in or .m function, (that is, it represents a set of overloaded functions), then the data type of the arguments x1 through xn determines which function is dispatched to.

[y1, y2, ...] = feval(fname, x1, ..., xn). If fname is a quoted string containing the name of a function (usually defined within file having a .m file extension), then feval(fname, x1, ..., xn) evaluates that function at the given arguments. The fname parameter must be a simple function name; it cannot contain path information.

Tips

The following two statements are equivalent.

[V,D] = eig(A)
[V,D] = feval(@eig, A)

Nested functions are not accessible to feval. To call a nested function, you must either call it directly by name, or construct a function handle for it using the @ operator.

Examples

The following example passes a function handle, fhandle, in a call to fminbnd. The fhandle argument is a handle to the humps function.

fhandle = @humps;
x = fminbnd(fhandle, 0.3, 1);

The fminbnd function uses feval to evaluate the function handle that was passed in.

function [xf, fval, exitflag, output] = ...
    fminbnd(funfcn, ax, bx, options, varargin)
            .
            .
            .
fx = feval(funfcn, x, varargin{:});

See Also

assignin | builtin | eval | evalin | function_handle | functions

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS