title: B-Spline Basic function Matlab recursive
body: <p>I'm trying to make a B-Spline Function</p>
  
  <p>first i set the variables and made the Knot vector </p>
  
  <pre><code># cmpp.m
  % Set variables
  k = 3;              % (8 mod 2 + 2 + 1) 
  p = k - 1;          % Order = 2
  n = 2*k - 1;        % Control points = 5
  l = n + p + 1;      % Vector size n + p + 1 = 8
  
  % Create the Knot vector
  % Kv = [0 0 0 1 2 3 3 3] size = 8
  knoten = 0;         % set all knots to 0
  Kv = [];
  for j=1:1:l 
      Kv = [ Kv 0 ]; 
  end
  
  for i=1:1:l
      if (i &gt; n)
          if (i &lt;= n) 
              Kv(i) = knoten + 1;
              knoten = knoten + 1;
          else
              Kv(i) = knoten;
          end
      else
          Kv(i) = knoten;
      end
  end
  </code></pre>
  
  <p>then i worte a function to create the basic function </p>
  
  <pre><code># f.m
  function N = f(N,t,i,k,u,x,s)
  if (u &lt; x)
      N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) + (((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));
      if ((u &gt;= t(i)) &amp;&amp; (u &lt; t(i+1)))
          N(i,1) = 1;
      else
          N(i,1) = 0;
      end
  end
  end
  </code></pre>
  
  <p>and called it in <code>cmpp.m</code></p>
  
  <pre><code># cmpp.m
  ...
  ...
  ...
  N = zeros(l,k);
  x = (n+1) - (k-1);
  s = 1;
  N = [N f(N,Kv,1,k,0,x,s)];
  </code></pre>
  
  <p>but i get always this error in Matlab</p>
  
  <pre><code>&gt;&gt; cmpp
  Subscripted assignment dimension mismatch.
  
  Error in f (line 3)
      N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) +
      (((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));
  
  Error in cmpp (line 32)
  N = [N f(N,Kv,1,k,0,x,s)]
  </code></pre>