]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/cumsumskipnan.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / cumsumskipnan.m
1 function [x] = cumsumskipnan(x, DIM)
2 % CUMSUMSKIPNAN  Cumulative sum while skiping NaN's. 
3 % If DIM is omitted, it defaults to the first non-singleton dimension.
4
5 % Y = cumsumskipnan(x [,DIM])
6
7 % x     input data      
8 % DIM   dimension (default: [])
9 % y     resulting sum
10 %
11 % see also: CUMSUM, SUMSKIPNAN
12
13
14 %    This program is free software; you can redistribute it and/or modify
15 %    it under the terms of the GNU General Public License as published by
16 %    the Free Software Foundation; either version 3 of the License, or
17 %    (at your option) any later version.
18 %
19 %    This program is distributed in the hope that it will be useful,
20 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
21 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 %    GNU General Public License for more details.
23 %
24 %    You should have received a copy of the GNU General Public License
25 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
26
27 %       $Id$
28 %       Copyright (C) 2011 by Alois Schloegl <alois.schloegl@gmail.com> 
29 %       This function is part of the NaN-toolbox
30 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
31
32
33 %%% TODO: implement as mex-function
34
35 i = isnan(x);
36 x(i) = 0;
37
38 if nargin==2,
39         x = cumsum(x,DIM);
40         x(i) = NaN;
41 elseif nargin==1,
42         x = cumsum(x);
43         x(i) = NaN;
44 else
45         help cumsumskipnan
46 end;    
47
48
49