title: MATLAB - Make table from for loop
body: <p>I have the following code</p>
  
  <pre><code>x=[1 0.5 0.5]', iter=0; dxnorm=1;
  while dxnorm&gt;0.5e-4 &amp; iter&lt;10
      f=[cos(x(1))+cos(x(2))+cos(x(3))-2
          sin(x(1))+sin(x(2))+sin(x(3))
          tan(x(1))-2.*tan(x(2))+tan(x(3))
          ]                          ;
      J=[-sin(x(1))     -sin(x(2))      -sin(x(3))
          cos(x(1))      cos(x(2))      cos(x(3))
          tan(x(1)).^2 + 1    -2*tan(x(2)).^2 - 2     tan(x(3)).^2 + 1];
      dx=-J\f;
      x=x+dx;
      dxnorm = norm(dx,inf), iter=iter+1;
  end
  x, iter
  </code></pre>
  
  <p>and I would like to store the results after every iteration in a table so I can see how the result changes as the time goes on. I have seen some different codes on how to do this (that is, you have a for loop, and store every result in a table) but none that I have been able to implement. Any ideas how I could do this? For example, I did watch some examples from here, <a href="http://www.mathworks.com/matlabcentral/answers/163572-creating-a-table-of-values-from-for-loops" rel="nofollow">http://www.mathworks.com/matlabcentral/answers/163572-creating-a-table-of-values-from-for-loops</a> but as I said wasn't able to implement any of these.</p>