title: How to avoid element being overwritten by second loop?
body: <p>I want to generate an array using two loops and a given equation. In my code, the first for-loop overwrites each time the elements that were generated in the previous run. My array ends up having only the last set of elements (for a=9). Here is the code:</p>
  
  <pre><code>%Pixel information generated 
  
  n=3
  m=3
  
  for a=7:9
  
      for r=1:3
        k(r)=a+ (r-1)*(n*m)
        disp(k);
        r=r+1
      end
  a=a+1
  end
  </code></pre>
  
  <p>How can I avoid this and obtain all values of <code>K</code> for each value of "a"?</p>
  
  <p>Thanks
  Manoj</p>