|
FreeMat
|
Section: Array Generation and Manipulations
Returns a dense column vector containing the nonzero elements of the argument matrix. The syntax for its use is
y = nonzeros(x)
where x is the argument array. The argument matrix may be sparse as well as dense.
Here is an example of using nonzeros on a sparse matrix.
--> a = rand(8); a(a>0.2) = 0;
--> A = sparse(a)
A =
1 1 0.0596135
7 1 0.0283717
8 1 0.0337801
5 2 0.0700267
1 4 0.0881058
4 4 0.00699947
5 4 0.0494723
8 5 0.0420057
4 6 0.153486
7 6 0.0654851
1 7 0.174397
4 7 0.0684673
2 8 0.13853
--> nonzeros(A)
ans =
0.0596
0.0284
0.0338
0.0700
0.0881
0.0070
0.0495
0.0420
0.1535
0.0655
0.1744
0.0685
0.1385