NONZEROS Retrieve Nonzero Matrix Entries

Section: Array Generation and Manipulations

USAGE

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.

Example

Here is an example of using nonzeros on a sparse matrix.
--> a = rand(8); a(a>0.2) = 0;
--> A = sparse(a)
A = 
  <double>  - size: [8 8]
	Matrix is sparse with 19 nonzeros
--> nonzeros(A)
ans = 
  <double>  - size: [19 1]
 
Columns 1 to 1
 0.176674010050446140  
 0.033683807507751351  
 0.194322375610502585  
 0.084649178177801043  
 0.020008763017926312  
 0.188428603899843505  
 0.051904351720045594  
 0.074500456122603476  
 0.053789324283652684  
 0.083758587485404656  
 0.055984727118660982  
 0.165667948292393286  
 0.043324985788029791  
 0.178793085670626128  
 0.137363231638781280  
 0.170226608135686464  
 0.051293470679533937  
 0.176704939516551085  
 0.052829621634443269