nnz 函数
Number of nonzero matrix elements
矩阵非零元素的数量
Syntax
语法
n = nnz(X)
Description
描述
n = nnz(X) returns the number of nonzero elements in matrix X.
n=nnz(X)返回矩阵X中的非零元素的数目。
The density of a sparse matrix is nnz(X)/prod(size(X)).
稀疏矩阵的密度是:nnz(X)/prod(size(X))。
Examples
例如:
The matrix
矩阵:
w = sparse(wilkinson(21));
is a tridiagonal matrix with 20 nonzeros on each of three diagonals, so nnz(w) = 60.
是一个在每三条对角线上带有20个非零元素的三对角线矩阵,因此nnz(w)=60。