File: nancumsum.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (37 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [s]=nancumsum(x,orient)
//
//This function returns in scalar or vector s the sum of the
//values (ignoring the NANs) of  a vector or matrix (real or
//complex) x.
//
//This function  for a vector or a  matrix x, s=nancumsum(x)
//(or, equivalently  s=nancumsum(x,'*') returns in  scalar s
//the cumulative sum (ignoring  the NANs) of all the entries
//of x taken columnwise.
//
//s=nancumsum(x,'r')  (or,  equivalently,  s=nancumsum(x,1))
//returns in  the cols(x) sized vector s  the cumulative sum
//(ignoring    the    NANs)    of    the    rows    of    x:
//s(:,i)=nancumsum(x(:,i))
//
//s=nancumsum(x,'c')  (or,  equivalently,  s=nancumsum(x,2))
//returns in  the rows(x) sized vector s  the cumulative sum
//(ignoring     NANs)    of     the     columns    of     x:
//s(i,:)=nancumsum(x(i,:))
//
//For the  last two cases,  if a row  or column is  in whole
//composed of NAN, the corresponding place of s will contain
//a NAN.
//
//author: carlos klimann
//
//date: 2003-09-03
//
  if argn(2)==1 then  orient='*',end
  isn=isnan(x)
  x(isn)=0
  s=cumsum(x,orient)
  s(find(and(isn,orient)))=%nan
 
endfunction