]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/geomean.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / geomean.m
1 function [y] = geomean(x,DIM,W)
2 % GEOMEAN calculates the geomentric mean of data elements. 
3
4 %       y = geomean(x [,DIM [,W]])   is the same as 
5 %       y = mean(x,'G' [,DIM]) 
6 %
7 % DIM   dimension
8 %       1 STD of columns
9 %       2 STD of rows
10 %       default or []: first DIMENSION, with more than 1 element
11 % W     weights to compute weighted mean (default: [])
12 %       if W=[], all weights are 1. 
13 %       number of elements in W must match size(x,DIM) 
14 %
15 % features:
16 % - can deal with NaN's (missing values)
17 % - weighting of data 
18 % - dimension argument also in Octave
19 % - compatible to Matlab and Octave
20 %
21 % see also: SUMSKIPNAN, MEAN, HARMMEAN
22 %
23 %    This program is free software; you can redistribute it and/or modify
24 %    it under the terms of the GNU General Public License as published by
25 %    the Free Software Foundation; either version 3 of the License, or
26 %    (at your option) any later version.
27 %
28 %    This program is distributed in the hope that it will be useful,
29 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
30 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 %    GNU General Public License for more details.
32 %
33 %    You should have received a copy of the GNU General Public License
34 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
35
36
37 %       $Id: geomean.m 8223 2011-04-20 09:16:06Z schloegl $ 
38 %       Copyright (C) 2000-2002,2009 by Alois Schloegl <alois.schloegl@gmail.com>
39 %       This is part of the NaN-toolbox. For more details see
40 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
41
42
43 if nargin<2
44         DIM=min(find(size(x)>1));
45         if isempty(DIM), DIM=1; end;
46 end
47 if nargin<3
48         W = [];
49 end;
50
51 [y, n] = sumskipnan(log(x),DIM,W);
52 y = exp (y./n);
53