title: Sparse Matrix Assignment becomes very slow in Matlab
body: <p>I am filling a sparse matrix P (230k,290k) with values coming from a text file which I read line by line, here is the (simplified) code</p>
  
  <pre><code>while ...
              C = textscan(text_line,'%d','delimiter',',','EmptyValue', 0);
              line_number = line_number+1;
              P(line_number,:)=C{1};
  end
  </code></pre>
  
  <p>the problem I have is that while at the beginning the</p>
  
  <pre><code>P(line_number,:)=C{1};
  </code></pre>
  
  <p>statement is fast, after a few thousands lines become exterely slow, I guess because Matlab need to find the memory space to allocate every time. Is there a way to pre-allocate memory with sparse matrixes? I don't think so but maybe I am missing something. Any other advise which can speed up the operation (e.g. having a lot of free RAM can make the difference?) </p>