home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPARFUN.DI$ / SPFUN.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  398 b   |  12 lines

  1. function f = spfun(fun,s)
  2. %SPFUN     Apply a function only to the nonzero entries.
  3. %    F = SPFUN('fun',S) evaluates fun(s) on the nonzero elements of S.
  4. %    e.g. F = SPFUN('exp',S) has the same sparsity pattern as S
  5. %    (except for underflow), whereas EXP(S) has 1's where S has 0's.
  6.  
  7. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  8.  
  9. [i,j,x] = find(s);
  10. f = eval( [ 'sparse(i,j,'  fun '(x))' ] );
  11.  
  12.