~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/statistics/nanmean.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [m]=nanmean(x,orient)
 
2
//
 
3
//This function returns in scalar m the mean of the values (ignoring the
 
4
//NANs) of  a  vector  or  matrix  x.
 
5
//
 
6
//For  a vector   or  matrix x,  m=nanmean(x) or  m=nanmean(x,'*')
 
7
//returns in scalar m the mean of all the entries (ignoring the NANs) of
 
8
//x.
 
9
//
 
10
//m=nanmean(x,'r')  (or,   equivalently, m=nanmean(x,1))  returns in
 
11
//each entry of  the row vector  m  of type 1xsize(x,'c')  the mean of
 
12
//each column of x (ignoring the NANs).
 
13
//
 
14
//m=nanmeanf(x,'c')(or, equivalently, m=nanmean(x,2))  returns    in
 
15
//each entry of the column vector m of  type size(x,'c')x1 the mean of
 
16
//each row of x (ignoring the NANs).
 
17
//
 
18
//author: carlos klimann
 
19
//
 
20
//date: 2000-02-15
 
21
//
 
22
  if argn(2)==0 then error('nanmean requires one or two inputs.'), end
 
23
  if argn(2)==1 then  orient='*',end
 
24
  //replace nans by 0
 
25
  isn=isnan(x)
 
26
  x(isn)=0
 
27
 
 
28
  N=size(x,orient)-sum(bool2s(isn),orient)
 
29
  allnans=find(N==0)
 
30
  N(allnans)=1
 
31
  m = sum(x,orient)./N;
 
32
  m(allnans)=%nan
 
33
 
 
34
endfunction