您的位置:首页 > 编程语言 > MATLAB

[Matlab] feval使用

2015-06-26 10:51 645 查看
查看doc feval:[y1, y2, ...] = feval(fhandle, x1, ..., xn)[y1, y2, ...] = feval(fname, x1, ..., xn)

[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.

意思很清楚,feveal就是把已知数据和符号带入已定义好的函数或函数句柄中,简单理解就是求函数的值用的。

例如:

假设需要调用的函数foo定义如下:

function x=foo(a,b)

x=a*b;

若在main函数中用feval调用foo,可以有以下几种方式1. result=feval('foo',3,15);

2. result=feval(@foo,3,16); %这里@foo即句柄等价于result = x(3,15)。

详细参见: http://www.cnblogs.com/begtostudy/archive/2012/06/27/2565920.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: