title: Efficient code for draw a sierpinski triangle with matlab
body: <p>Following is my code:</p>
  
  <pre><code>function sierpinski(A, B, C, n)
      if n == 0
          patch([A(1), B(1), C(1)], [A(2), B(2), C(2)], [0.0 0.0 0.0]);
      else
         sierpinski(A, (A + B)/2, (A + C)/2, n-1);
         sierpinski(B, (B + A)/2, (B + C)/2, n-1);
         sierpinski(C, (C + A)/2, (C + B)/2, n-1);
  end
  
  % sierpinski([0 0], [1 0], [.5 .8], 8)
  </code></pre>
  
  <p>It's not very effectly. I want to first generating all data then patched, but I don't know how to correctly used. Also, can my code be written use for loops? </p>