MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何解决“未定义的函数或变量” (https://www.labfans.com/bbs/showthread.php?t=26169)

poster 2019-12-14 20:13

如何解决“未定义的函数或变量”
 
运行以下代码时,我不断收到错误'未定义函数或变量'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); % 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= threshold Test_X=Test_x.*avg_x1; % Give Zero matrix end end [B]谢谢您的所有帮助:)[/B]



[B]回答:[/B]

您将得到错误??? Undefined function or variable 'Test_x'.如果D的初始值小于5,则代码将在最后一行执行Test_X=Test_x.*avg_x1;无需先将Test_x设置为任何值。您还必须将avg_x1初始化为其他内容,否则将对该变量获得相同的错误。



[url=https://stackoverflow.com/questions/4686016]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:18

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.