title: For loop output as an array
body: <p>I wrote a code in Matlab which I predefine the variable "a" and then set up a for loop of 5 iterations where the variable "a" goes through some basic operations. However, the for loop output only saves the fifth iteration of "a." How do I save all 5 iterations in a 1x5 array?</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>a = 10;
  k = 0.5;
  n = 2;
  for m = 1:5
      a = a + (a*k) + n;
  end
  </code></pre>
  
  <p>Edit:
  I just found it that I have to create a new variable.</p>
  
  <pre><code>a = 10;
  k = 0.5;
  n = 2;
  a_n = zeros(1,5);
  
  for m = 1:5
      a = a + (a*k) + n;
      a_n(m) = a;
  end
  </code></pre>