Mercurial > octave-antonio
annotate scripts/sparse/spfun.m @ 10687:a8ce6bdecce5
Improve documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Jun 2010 20:22:38 -0700 |
parents | 16f53d29049f |
children | c776f063fefe |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 |
2 ## David Bateman and Andy Adler | |
5164 | 3 ## |
7016 | 4 ## This file is part of Octave. |
5164 | 5 ## |
7016 | 6 ## Octave is free software; you can redistribute it and/or modify it |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
5164 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5164 | 19 |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {@var{y} =} spfun (@var{f},@var{x}) | |
22 ## Compute @code{f(@var{x})} for the non-zero values of @var{x}. | |
23 ## This results in a sparse matrix with the same structure as | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## @var{x}. The function @var{f} can be passed as a string, a |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
25 ## function handle, or an inline function. |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
26 ## @seealso{arrayfun, cellfun, structfun} |
5164 | 27 ## @end deftypefn |
28 | |
6498 | 29 function t = spfun (f, s) |
30 | |
5164 | 31 if (nargin != 2) |
6046 | 32 print_usage (); |
5164 | 33 endif |
34 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7151
diff
changeset
|
35 [i, j, v] = find (s); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7151
diff
changeset
|
36 [m, n] = size (s); |
5164 | 37 |
6220 | 38 if (isa (f, "function_handle") || isa (f, "inline function")) |
6498 | 39 t = sparse (i, j, f(v), m, n); |
5164 | 40 else |
6498 | 41 t = sparse(i, j, feval (f, v), m, n); |
5164 | 42 endif |
43 | |
44 endfunction | |
45 | |
46 %!assert(spfun('exp',[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0])) | |
47 %!assert(spfun('exp',sparse([1,2;3,0])),sparse([exp(1),exp(2);exp(3),0])) | |
48 %!assert(spfun(@exp,[1,2;3,0]),sparse([exp(1),exp(2);exp(3),0])) | |
49 %!assert(spfun(@exp,sparse([1,2;3,0])),sparse([exp(1),exp(2);exp(3),0])) | |
50 |