| MATLAB Function Reference | ![]() |
Syntax
[y1,y2,...] = feval(fhandle,x1,...,xn) [y1,y2,...] = feval(function,x1,...,xn)
Description
[y1,y2,...] = feval(fhandle,x1,...,xn)
使用引數 x1 到 xn來運算函式處理(function
handle) fhandle。若函式處理( function handle)超過1個內建函式( built-in)或M檔案(表示這是一組包含過多函式的集合),
則 x1 到 xn 的資料型態決定了哪個函式要先處理。(determines which function
is dispatched to)
[y1,y2...] = feval(function,x1,...,xn)
若 function
為以引號來包住某個函式名稱的字串(通常定義在M檔案中),則 feval(function,x1,...,xn)
以所給定的函式和其引數來做運算。而 function 一定是單一函式的名稱,也不能包含路徑。
Note
The preferred means of evaluating a function by reference is to use a function handle. To support backward compatibility, feval also accepts a function name string as a first argument. However, function handles offer the additional performance, reliability, and source file control benefits listed in the section An Overview of Function Handles.
|
Remarks
[V,D] = eig(A) [V,D] = feval(@eig,A)
Examples
下列的範例在呼叫 fminbnd.時傳一個函式處理(function handle)fhandle。
而 fhandle 是對 humps 函式的處理。( is a handle to the humps function.)
fhandle = @humps; x = fminbnd(fhandle, 0.3, 1);
fminbnd 使用 feval
來運算所傳入的函式處理。( evaluate the function handle that was passed in.)
function [xf,fval,exitflag,output] = ...
fminbnd(funfcn,ax,bx,options,varargin)
.
.
.
fx = feval(funfcn,x,varargin{:});
下列範例中, @deblank 回傳函式處理(function handle)給 fhandle. Examining the handle using functions(fhandle) reveals that it is bound to two M-files that implement the deblank function. The default, strfun\ deblank.m, handles most argument types. However, the function is overloaded by a second M-file (in the @cell subdirectory) to handle cell array arguments as well.
fhandle = @deblank;
ff = functions(fhandle);
ff.default
ans =
matlabroot\toolbox\matlab\strfun\deblank.m
ff.methods
ans =
cell: 'matlabroot\toolbox\matlab\strfun\@cell\deblank.m'
當函式處理運算到細胞陣列(cell array)時, feval
從引數的型態中決定適當的函式來執行,而此函式是放在 strfun\@cell中。
feval(fhandle, {'string ','with ','blanks '})
ans =
'string' 'with' 'blanks'
See Also
assignin, function_handle, functions, builtin, eval, evalin
| ferror | fft | ![]() |