如何解决'未定义的函数或变量'
问题描述:
当我运行下面的代码时,我总是收到错误'未定义函数或变量'Test_x'。为什么我收到此错误?如何解决'未定义的函数或变量'
下面是我到目前为止,
for D=max(max(X)) % Find max value
if D >= 5 % For only when at least one value >= the threshold
sumx=conv2(X,kernel,'same'); % Compute the sum of neighbors for each pixel
nx=conv2(double(X>0),kernel,'same'); % Compute the number of non-zero neighbors
avg_x=X;
avg_x(avg_x<5)=0;
index=(avg_x>=5); % Find logical index of pixels >=40
avg_x(index)=sumx(index)./max(nx(index),1); % Center or average of the nonzeros
avg_x1=(avg_x>0);
tmp_x=avg_x;
maxVal=max(avg_x(:))+1;
tmp_x(tmp_x==0)=maxVal; % Replace all the zeros in the tmp_Z1 with a larger value
tmp_x=imerode(tmp_x,kernel);
Test_x=X>=tmp_x; % Put one wherever new_Z1(k)>=tmp_Z1(k)
Test=Test_x+avg_x1;
Test_X=(Test>0);
elseif D<5 % Use when there is no value >= threshold
Test_X=Test_x.*avg_x1; % Give Zero matrix
end
end
感谢您对您的所有帮助:)
答
您将得到错误??? Undefined function or variable 'Test_x'.
在你的代码如果D
初始值小于5以上,在这种情况下,您的代码将执行最后一行Test_X=Test_x.*avg_x1;
,而无需先将Test_x
设置为任何内容。你也必须初始化avg_x1
,否则你会得到同样的错误。
非常感谢..我只是修复了他们.. – Nadhris 2011-01-17 11:34:55