窗函数的feval错误

时间:2017-12-20 00:17:50

标签: matlab

我遇到此错误的问题:

使用feval时出错

  

参数必须包含字符串或function_handle。

窗口错误(第54行)

  

w = feval(wname,N,varargin {:});

这是一个窗函数:

function varargout = window(wname,N,varargin)
%WINDOW Window function gateway.
%   WINDOW(@WNAME,N) returns an N-point window of type specified
%   by the function handle @WNAME in a column vector.  @WNAME can
%   be any valid window function name, for example:
%
%   @bartlett       - Bartlett window.
%   @barthannwin    - Modified Bartlett-Hanning window. 
%   @blackman       - Blackman window.
%   @blackmanharris - Minimum 4-term Blackman-Harris window.
%   @bohmanwin      - Bohman window.
%   @chebwin        - Chebyshev window.
%   @flattopwin     - Flat Top window.
%   @gausswin       - Gaussian window.
%   @hamming        - Hamming window.
%   @hann           - Hann window.
%   @kaiser         - Kaiser window.
%   @nuttallwin     - Nuttall defined minimum 4-term Blackman-Harris window.
%   @parzenwin      - Parzen (de la Valle-Poussin) window.
%   @rectwin        - Rectangular window.
%   @taylorwin      - Taylor window.
%   @tukeywin       - Tukey window.
%   @triang         - Triangular window.
%
%   WINDOW(@WNAME,N,OPT1,OPT2) designs the window with the optional input
%   arguments specified in OPT1 and OPT2. To see what the optional input
%   arguments are, see the help for the individual windows, for example,
%   KAISER or CHEBWIN.
%
%   WINDOW launches the Window Design & Analysis Tool (WinTool).
%
%   EXAMPLE: 
%      N  = 100;
%      w  = window(@blackmanharris,N);
%      w1 = window(@gausswin,N,2.5);
%      w2 = window(@taylorwin,N,5,-35);
%      plot(1:N,[w,w1,w2]); axis([1 N 0 2]);
%      legend('Blackman-Harris','Gaussian','Taylor');
% 
%   See also BARTLETT, BARTHANNWIN, BLACKMAN, BLACKMANHARRIS, BOHMANWIN, 
%            CHEBWIN, GAUSSWIN, HAMMING, HANN, KAISER, NUTTALLWIN, PARZENWIN, 
%            RECTWIN, TAYLORWIN, TRIANG, TUKEYWIN, WINTOOL.

%    Author(s): P. Costa 
%    Copyright 1988-2008 The MathWorks, Inc.
%    $Revision: 1.14.4.2 $  $Date: 2008/07/09 18:13:44 $ 

if nargin == 0,
    wintool;
    w = [];
else
    % Create an N-point window specified in wname
    error(nargchk(2,inf,nargin,'struct')); % Function handle and order are required
    w = feval(wname,N,varargin{:});
end

if nargout > 0,
    varargout{1} = w;
end

% [EOF]

1 个答案:

答案 0 :(得分:0)

使用feval是一种糟糕的风格,因为它会降低你的代码的可读性。我建议,不要使用包含wname参数的函数名称的字符串调用窗口函数,而是使用文档中建议的函数句柄。 然后,您可以通过以下方式替换feval声明:

w = wname(N,varargin{:});

当您调用window()函数时,您必须传递函数句柄,而不是名称:

window(@bartlett,N)

如果在其他地方定义了函数bartlett(),这将有效。

如果您无法更改window()的主叫代码,请注意正确调用该功能,如上所示,或者

window('bartlett',N)

在这两种情况下都必须定义函数'bartlett'!