Main Content


Number of nonzero elements in fi object

Since R2020b



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

When X is a built-in MATLAB® type, floating-point fi object, or scaled double fi object, N is returned as a double. When X is a fixed-point fi object, N is returned as a uint32 if X has fewer than 232 elements. Otherwise, N is returned as a uint64.


collapse all

Create a fi object and determine the number of nonzero elements it contains.

p = fi([],1,24,12);
X = eye(2,3,'like',p)
X = 

     1     0     0
     0     1     0

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 24
        FractionLength: 12
N = nnz(X)
N =



Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi
Complex Number Support: Yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b

See Also