MATLAB Function Reference Previous page   Next Page
nnz

Number of nonzero matrix elements

Syntax

Description

n = nnz(X) returns the number of nonzero elements in matrix X.

The density of a sparse matrix is nnz(X)/prod(size(X)).

Examples

The matrix

is a tridiagonal matrix with 20 nonzeros on each of three diagonals, so nnz(w) = 60.

See Also

find, isa, nonzeros, nzmax, size, whos


Previous page  nextpow2 noanimate Next page

© 1994-2005 The MathWorks, Inc.