Use nonzeros to return the nonzero elements in a sparse matrix.
Create a 10-by-10 sparse matrix that contains a few nonzero elements. The typical display of sparse matrices shows a list of the nonzero values and their locations.
Nonzero elements, returned as a column vector. v is returned in
full-storage regardless of whether A is full or sparse. The elements
in v are ordered first by column subscript and then by row
subscript.
nonzeros gives the v, but not the indices
i and j, from [i,j,v] =
find(A).
Generally,
length(v) = nnz(A) <= nzmax(A) <= prod(size(A))
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
GPU Arrays Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.