开发者

How to solve 'undefined function or variable'

开发者 https://www.devze.com 2023-02-04 11:39 出处:网络
I keep getting error \' Undefined function or variable \'Test_x\' when I run the following codes.. Why do I receive this error??

I keep getting error ' Undefined function or variable 'Test_x' when I run the following codes.. Why do I receive this error??

Below is what I have so far,

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

Thank you for all your helps :)


You will get the error ??? Undefined function or variable 'Test_x'. in your code if the initial value of D is less than 5, in which case your code will execute the last line Test_X=Test_x.*avg_x1; without first setting Test_x to anything. You will also have to initialize avg_x1 to something as well, or else you will get the same error for that variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消