spfun
Apply function to nonzero sparse matrix elements
Syntax
Description
applies the functionF
= spfun(func
,S
)func
to the nonzero elements of a sparse matrixS
. The input argumentfunc
is a function handle to a function that takes one input argument.
This operation preserves the sparsity of the original matrixS
unless the functionfunc
returns zero for some nonzero elements ofS
.
Examples
Input Arguments
Tips
If
func
returns zero for inputs that are zero, you can usefunc(S)
to return the same results as callingspfun
on a sparse matrixS
.