nzmax
Reserved size for nonzero elements.
📝Syntax
v = nzmax(M)
📥Input Arguments
Parameter Description
M numeric, logical, or character array, sparse or full.
📤Output Arguments
Parameter Description
v a integer value.
📄Description

nzmax returns the amount of storage allocated for nonzero elements.

For full arrays, nzmax returns numel(M). For sparse matrices, it returns the reserved sparse storage capacity, which can be larger than nnz(M).

Sparse double, single, logical, complex double, and complex single matrices are supported. Stored zero values may contribute to the reserved capacity even though nnz ignores them.

💡Examples
I = [1 2 3];
J = [3 1 2];
V = [32 42 53];
sp = sparse(I, J, V, 5, 4, 10)
size(sp)
nnz(sp)
nzmax(sp)
S = sparse([1 2 1 2], [1 1 2 2], single([0 -0 complex(0, 0) complex(0, 2)]), 2, 2, 4);
[nnz(S), nzmax(S)]
🔗See Also
sparsennz
🕔Version History
Version Description
2.0.0 documented sparse single and reserved storage behavior
1.0.0 initial version
Edit this page on GitHub