Function Reference
— Function File: s = spalloc (r, c, nz)

Returns an empty sparse matrix of size r-by-c. As Octave resizes sparse matrices at the first opportunity, so that no additional space is needed, the argument nz is ignored. This function is provided only for compatibility reasons.

It should be noted that this means that code like

          k = 5;
          nz = r * k;
          s = spalloc (r, c, nz)
          for j = 1:c
            idx = randperm (r);
            s (:, j) = [zeros(r - k, 1); rand(k, 1)] (idx);
          endfor

will reallocate memory at each step. It is therefore vitally important that code like this is vectorized as much as possible.

See also: sparse nzmax