title: feval error nlfilter, reference to a cleared variable
body: <p>Here is a part of a function I am trying for testing a larger function. </p>
  
  <pre><code>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 
  </code></pre>
  
  <p>If I remove the <code>clear all</code> statement, then the following error appears,</p>
  
  <pre><code>Enter the lag = 1
  
  ld =
  
       1
  
  ??? Error using ==&gt; feval
  Undefined function or method 'dirvar' for input arguments of type 'double'.
  
  Error in ==&gt; nlfilter at 61
  b = mkconstarray(class(feval(fun,aa(1+rows,1+cols),params{:})), 0, size(a));
  
  Error in ==&gt; funct at 5
  A = nlfilter(I, [7 7], str2func(subfn));
  </code></pre>
  
  <p>Please <strong>ignore</strong> this part as I have now removed <code>clear all</code> statement as suggested in an answer below.
  When I run <code>funct('dirvar')</code> I am greeted with this error:</p>
  
  <pre><code>Enter the lag = 1
  
  ld =
  
       1
  
  ??? Reference to a cleared variable subfn.
  
  Error in ==&gt; funct at 6
  A = nlfilter(I, [7 7], str2func(subfn));
  </code></pre>
  
  <p>What might be the reason?</p>