spones - Replace nonzero sparse matrix elements with ones - MATLAB (original) (raw)
Main Content
Replace nonzero sparse matrix elements with ones
Description
R = spones(S)
generates a matrix R
with the same sparsity structure as S
, but with 1
'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)
and sum(r)
are equal, and are equal to nnz(S)
.
Extended Capabilities
The spones
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a