0
|
1 ## Copyright (C) 2001 Paul Kienzle |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## v = nansum (X [, dim]); |
|
18 ## nansum is identical to the sum function except that NaN values are |
|
19 ## treated as 0 and so ignored. If all values are NaN, the sum is |
|
20 ## returned as 0. [Is this behaviour compatible?] |
|
21 ## |
|
22 ## See also: nanmin, nanmax, nanmean, nanmedian |
|
23 function v = nansum (X, ...) |
|
24 if nargin < 1 |
|
25 usage ("v = nansum (X [, dim])"); |
|
26 else |
|
27 dfi = do_fortran_indexing; |
|
28 pzoi = prefer_zero_one_indexing; |
|
29 unwind_protect |
|
30 do_fortran_indexing = 1; |
|
31 prefer_zero_one_indexing = 1; |
|
32 |
|
33 X(isnan(X)) = 0; |
|
34 v = sum (X, all_va_args); |
|
35 unwind_protect_cleanup |
|
36 do_fortran_indexing = dfi; |
|
37 prefer_zero_one_indexing = pzoi; |
|
38 end_unwind_protect |
|
39 endif |
|
40 endfunction |