%% Location and Count of Nonzeros
% Use nonzeros, nnz, and find to locate and count nonzero matrix elements.
%
% Create a 10-by-10 random sparse matrix with 7% density of nonzeros.

A = sprand(10,10,0.07);

%
% Use nonzeros to find the values of the nonzero elements.

v = nonzeros(A)

%
% Use nnz to count the number of nonzeros.

n = nnz(A)

%
% Use find to get the indices and values of the nonzeros.

[i,j,v] = find(A)

%
% Copyright 2018 The MathWorks, Inc.