Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

feval

Evaluate function

Syntax

  • [y1,...,yN] = feval(fun,x1,...,xM)
    example

Description

example

[y1,...,yN] = feval(fun,x1,...,xM) evaluates a function using its name or its handle, and using the input arguments x1,...,xM.

The feval function follows same scoping and precedence rules as calling a function handle directly. For more information, see Create Function Handle.

Examples

collapse all

Round the value of pi to the nearest integer using the name of the function.

fun = 'round';
x1 = pi;
y = feval(fun,x1)
y =

     3

Round the value of pi to two digits to the right of the decimal point.

x2 = 2;
y = feval(fun,x1,x2)
y =

    3.1400

Input Arguments

collapse all

Function to evaluate, specified as a function name or a handle to a function. The function accepts M input arguments, and returns N output arguments. To specify fun as a function name, do not include path information.

Invoking feval with a function handle is equivalent to invoking the function handle directly.

Example: fun = 'cos'

Example: fun = @sin

Inputs to the evaluated function. The types of the inputs depend on the function, fun.

Output Arguments

collapse all

Outputs from evaluated function. The types of the outputs depend on the function, fun.

More About

collapse all

Tips

  • If you have a function handle, it is not necessary to use feval because you can invoke the function handle directly. The results of the following statements are equivalent.

    fh = @eig;
    [V,D] = fh(A)
    
    [V,D] = feval(@eig,A)
  • To evaluate a nested or local function using feval, use a function handle instead of the function name. For more information, see Call Local Functions Using Function Handles.

Introduced before R2006a


Was this topic helpful?