這是我嘗試測試更大功能的函數的一部分。feval錯誤nlfilter,清除變量的引用
function funct(subfn)
clear all; % this is now removed
clc;
I = rand(11,11);
ld = input('Enter the lag = ') % prompt for lag distance
A = nlfilter(I, [7 7], str2func(subfn));
% Subfunction
function [h] = dirvar(I)
c = (size(I)+1)/2
EW = I(c(1),c(2):end)
h = length(EW) - ld
end
% Subfunction
function [h] = diagvar(I)
c = (size(I)+1)/2
NE = diag(I(c(1):-1:1,c(2):end))
h = length(NE) - ld
end
end
如果我刪除clear all
語句,則出現以下錯誤,
Enter the lag = 1
ld =
1
??? Error using ==> feval
Undefined function or method 'dirvar' for input arguments of type 'double'.
Error in ==> nlfilter at 61
b = mkconstarray(class(feval(fun,aa(1+rows,1+cols),params{:})), 0, size(a));
Error in ==> funct at 5
A = nlfilter(I, [7 7], str2func(subfn));
請忽略這一部分,因爲我現在已經刪除clear all
聲明如下答覆建議。
Enter the lag = 1
ld =
1
??? Reference to a cleared variable subfn.
Error in ==> funct at 6
A = nlfilter(I, [7 7], str2func(subfn));
可能是什麼原因: 當我運行funct('dirvar')
我與這個錯誤招呼?
謝謝你指出正確的方向! – 2011-04-17 13:34:07