title: Vectorization of a loop in matlab
body: <p>I have a loop</p>
  
  <pre><code>for i = 2:K
      T(K,i) = ((4^(i-1))*T(K,i-1)-T(K-1,i-1))/(4^(i-1)-1); 
  end
  </code></pre>
  
  <p>where <code>T</code> is a two dimensional matrix (first element in given row, and all elements in rows above are already there) and <code>K</code> is a scalar.
  I have tried to vectorize this loop to make it faster like this:</p>
  
  <pre><code>i = 2:K;
  T(K,i) = ((4.^(i-1)).*T(K,i-1)-T(K-1,i-1))./(4.^(i-1)-1); 
  </code></pre>
  
  <p>it compiles, but it yields improper results. Can you tell me where am I making mistake?</p>
  
  <p>@EDIT:
  I have written this, but still the result is wrong</p>
  
  <pre><code>     i = 2:K;
       i2 = 1:(K-1);
       temp1 = T(K,i2)
       temp2 = T(K-1,i2)
       T(K,i) = ((4.^(i2)).*temp1-temp2)./(4.^(i2)-1); 
  </code></pre>