nnz

Finds the number of non-zero values in a matrix.

Syntax

n = nnz(a)

Inputs

a
A matrix.
Type: double | complex
Dimension: matrix

Outputs

n
The number of non-zero values.
Type: integer
Dimension: scalar

Example

m = [10,   0, 110,   0,  210, 260;
     20,   0,   0, 170, -220,   0;
      0,   0,   0, 180,  230,   0;
     40, -90,   0, 190,  240, 290;
      0,   0, 150,   0,    0,   0];
n = nnz(m)
n = 15