spalloc
Allocate space for an m × n sparse matrix.
Syntax
Section titled “Syntax”S = spalloc(m, n, nzmax)Description
Section titled “Description”Returns an empty m × n sparse matrix with storage pre-allocated for nzmax non-zero entries. Doesn’t insert any values — a placeholder for a sparse matrix you’ll fill incrementally without triggering reallocations on each assignment.
Examples
Section titled “Examples”S = spalloc(1000, 1000, 50); % allocate for up to 50 nonzerosfor i = 1:50 S(i, i) = i;end