nzmax
Amount of storage allocated for nonzero elements.
Category: Mathematics > Sparse Matrices
Syntax
n = nzmax(S)
Returns the number of elements of storage reserved for the nonzeros of S.
Description
A sparse matrix may reserve room for more nonzeros than it holds, so that filling it in later does not require repeated reallocation. nzmax reports that capacity, while nnz reports how much is used. For a full array the answer is simply the number of elements.
Input arguments
S- Sparse or full array.
Output arguments
n- Storage count. It is at least
nnz(S)for sparse input andnumel(S)for full input.
Example
Capacity versus use
S = sparse([1 2], [1 2], [3 4], 5, 5);
nnz(S)
nzmax(S) >= nnz(S)
nzmax(ones(2, 3))
Output
ans = 2
ans = logical
1
ans = 6
Notes
The reserved capacity can differ from MATLAB's, for example after spalloc, so compare nzmax against nnz rather than a fixed number.