title: Appending a vector to an empty MATLAB matrix
body: <p>I've got MATLAB code inserting n-dimensional points (n >1) into a matrix (<code>myPointMatrix</code>) and am having thoughts about how to insert the first point.</p>
  
  <p>Right now the program checks the size of <code>myPointMatrix</code> before inserting a point. If it is 1x1, <code>myPointMatrix</code> is set equal to the current point. Otherwise the current point is appended. This <code>if</code>-statement is only true once, but is evaluated each time I insert a point, which is very very often.</p>
  
  <p>Removing the <code>if</code> and trying to append to <code>myPointMatrix</code> makes MATLAB understandably complain about matrix dimensions not being consistent. Removing both the <code>if</code>-statement and the inialization of <code>myPointMatrix = 0</code> causes MATLAB to find <code>myPointMatrix</code> undefined. Also understandable.</p>
  
  <p>How do I initialize <code>myPointMatrix</code> so that I can remove the <code>if</code>-statement? Or is there some other smart solution?</p>
  
  <pre><code>myPointMatrix = 0;
  for x=0:limit
      for y=0:limit
          for z=0:limit
              tempPoint = [x y z];
              if (length(myPointMatrix) == 1)
                  myPointMatrix = tempPoint;
              else
                  myPointMatrix = [myPointMatrix; tempPoint];
              end
          end
      end
  end
  </code></pre>