Back to Sparse Matrices
spfun
Apply function to nonzero sparse matrix elements
Syntax
F = spfun(func, S)
Description
Applies the function func to the nonzero elements of sparse matrix S. The sparsity pattern is preserved.
Parameters
| Name | Description |
|---|---|
| func | Function handle to apply (e.g., @sqrt, @exp) |
| S | Sparse matrix |
Returns
Sparse matrix with function applied to nonzeros
Examples
Try It
>> full(spfun(@sqrt, sparse([4 0; 0 9])))