title: Variable undefined in simple matlab function
body: <p>I cannot understand why I am receiving the following error:</p>
  
  <pre><code>error: 'y' undefined near line 7 column 22
  error: execution exception in odefun.m
  </code></pre>
  
  <p>For this function:</p>
  
  <pre><code>function s = odefun(t, y)
          global K = [ 0.5; 3; 1; 4; 1; 5 ];
          function ret = k(n)
                  global K;
                  ret = K(n+1);
          end
          s = zeros(6,1);
          s(1) = k(0) -k(1) * y(1) * y(2);
          s(2) = k(2) - k(1) * y(1) * y(2);
          s(3) = k(1) * y(1) * y(2) - k(3) * y(3);
          s(4) = k(1) * y(1) * y(2) - k(2) * y(4);
          s(5) = k(3) * y(3) - k(4) * y(5);
          s(6) = k(3) * y(3) - k(5) * y(6);
  end
  
  y0 = [1; 1; 1/2; 0; 0; 0]
  [t, y] = ode45(odefun, [0 10], y0)
  </code></pre>
  
  <p>Obviously I am a beginner with Matlab and any help is much appreciated.</p>