spones
Replace nonzero sparse matrix elements with ones
Syntax
R = spones(S)
Description
R = spones(S)
generates a matrixR
with the same sparsity structure asS
, but with1
's in the nonzero positions.
Examples
c = sum(spones(S))
is the number of nonzeros in each column.
r = sum(spones(S'))'
is the number of nonzeros in each row.
sum(c)
andsum(r)
are equal, and are equal tonnz(S)
.
Extended Capabilities
Introduced before R2006a
Was this topic helpful?