| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
n = nnz(X)
n = nnz(X) returns the number of nonzero elements in matrix X.
The density of a sparse matrix is nnz(X)/prod(size(X)).
The matrix
w = sparse(wilkinson(21));
is a tridiagonal matrix with 20 nonzeros on each of three diagonals, so nnz(w) = 60.
find, isa, nonzeros, nzmax, size, whos
![]() | nextpow2 | noanimate | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |