Skip to content

spones

Replace non-zero entries with 1s.

S = spones(R)

Returns a sparse matrix the same shape as R whose stored entries are all 1. The structural pattern is preserved — useful for capturing or comparing sparsity patterns between matrices.

A = sparse([1 2; 3 0; 0 4]);
spones(A) % stored entries replaced with 1s
  • sparse — Create a sparse matrix.
  • ones — Array of all ones.