## NNZ Number of Nonzeros

Section: Sparse Matrix Support

### Usage

Returns the number of nonzero elements in a matrix. The general format for its use is

       y = nnz(x)

This function returns the number of nonzero elements in a matrix or array. This function works for both sparse and non-sparse arrays. For

### Example

    --> a = [1,0,0,5;0,3,2,0]

    a =

     1 0 0 5
     0 3 2 0

    --> nnz(a)

    ans =

     4

    --> A = sparse(a)

    A =
    	Matrix is sparse with 4 nonzeros
    --> nnz(A)

    ans =

     4

    -->
    quit