Why is the Matlab function “feval” needed?

后端 未结 3 1357
灰色年华
灰色年华 2020-12-31 02:28

A function handle can be used to call a function, e.g.

f = @sin;
val = f(1.0);

so why is fev

相关标签:
3条回答
  • 2020-12-31 02:52

    For feval, the first argument can be a quoted string, giving you more flexibility than a function handle. You could do things like having functions with a base name followed by an index as in fn1, fn2, fn3, and then invoke these dynamically using feval(['fn', num2str(k)], x, y, z);.

    0 讨论(0)
  • 2020-12-31 02:59

    Not necessarily always you know what function is supposed to used; there are many examples

    here is a silly example: let, in a text file after each number, different word that can be evaluated as a mathematical function, like, mean, min, max, square are represented, and the task is calculating the result after each like,

    2,square,2,power,4,log,10 ...
    

    and you want to write a program to go through this text and calculate the final result ...

    another example is for example, I want to define a plot function with user input function handle f, so it must be in a way flexible ...

    pfun=@(f,x) plot(f(x))
    
    0 讨论(0)
  • 2020-12-31 03:00

    Until Release 14 (MATLAB 7), feval was the way to evaluate a function handle... or to evaluate functions when they are specified by their name.

    Source: Mental model for feval().

    0 讨论(0)
提交回复
热议问题