title: preallocation of memory in matlab / octave
body: <p>I preallocate memory for a large array but the new data appends at the end of the array instead of over writing the data how can I fix this.  So I can preallocate memory for a large array. </p>
  
  <p>note the array is 44101x5001 I just used smaller numbers in the example.</p>
  
  <p>Example:</p>
  
  <pre><code>clear all
  xfreq=zeros(10,10); %allocate memory
  
  for ww=1:1:10
       xfreq_new = xfreq(:,1)+1+ww;
       xfreq=[xfreq xfreq_new]; %would like this to over write and append the new data where the preallocated memory of zeros are instead of appending to the end of it.
  end
  </code></pre>
  
  <p>If you run this you'll notice that it appends the ones instead of over writing the zeros.</p>
  
  <p>Aloha
  Rick</p>
  
  <p>Hopefully this explains things better
  Allocated array</p>
  
  <p>1)Allocated memory of zeros</p>
  
  <pre><code>[0 0 0 0 0
  0 0 0 0 0
  0 0 0 0 0]
  </code></pre>
  
  <p>2) Overwriting allocated memory of zeros with a number, the number could be anything not just the number one, I used the number one as an example</p>
  
  <pre><code>[1 0 0 0 0
  1 0 0 0 0
  1 0 0 0 0]
  </code></pre>
  
  <p>3) Still Overwriting of allocated memory zeros with a number, the number could be anything not just the number one, I used the number one as an example</p>
  
  <pre><code>[1 1 0 0 0
  1 1 0 0 0
  1 1 0 0 0]
  </code></pre>
  
  <p>the problem is with this line
   xfreq=[xfreq xfreq_new]; %would like this to over write and append the new data where the preallocated memory of zeros are instead of appending to the end of it.
      end</p>