SPONES Sparse Ones Function

Section: Sparse Matrix Support

Usage

Returns a sparse float matrix with ones where the argument matrix has nonzero values. The general syntax for it is
  y = spones(x)

where x is a matrix (it may be full or sparse). The output matrix y is the same size as x, has type float, and contains ones in the nonzero positions of x.

Examples

Here are some examples of the spones function
--> a = [1,0,3,0,5;0,0,2,3,0;1,0,0,0,1]
a = 
  <int32>  - size: [3 5]
 
Columns 1 to 5
 1  0  3  0  5  
 0  0  2  3  0  
 1  0  0  0  1  
--> b = spones(a)
b = 
  <float>  - size: [3 5]
	Matrix is sparse with 7 nonzeros
--> full(b)
ans = 
  <float>  - size: [3 5]
 
Columns 1 to 5
 1  0  1  0  1  
 0  0  1  1  0  
 1  0  0  0  1