spones

Set non-zero matrix elements to 1.

Syntax

s = spones(m)

s = spones(m, n)

s = spones(dim)

Inputs

m
A sparse or full matrix.
Type: integer
Dimension: matrix

Outputs

s
A sparse matrix with the non-zero input elements replaced by 1.
Type: integer
Dimension: matrix

Example

a(1, 1) =  1;  a(1, 2) =  6;  a(1, 3) =  0;  a(1, 4) = 16;
a(2, 1) =  2;  a(2, 2) =  0;  a(2, 3) =  0;  a(2, 4) =  0;
a(3, 1) =  0;  a(3, 2) =  7;  a(3, 3) = 13;  a(3, 4) = 18;
a(4, 1) =  4;  a(4, 2) =  0;  a(4, 3) = 14;  a(4, 4) =  0; 
s = spones(sparse(a))
s = sparse [4 x 4], nnz = 9
[1,1] 1
[2,1] 1
[4,1] 1
[1,2] 1
[3,2] 1
[3,3] 1
[4,3] 1
[1,4] 1
[3,4] 1