1 function [y] = geomean(x,DIM,W)
2 % GEOMEAN calculates the geomentric mean of data elements.
4 % y = geomean(x [,DIM [,W]]) is the same as
5 % y = mean(x,'G' [,DIM])
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)
16 % - can deal with NaN's (missing values)
18 % - dimension argument also in Octave
19 % - compatible to Matlab and Octave
21 % see also: SUMSKIPNAN, MEAN, HARMMEAN
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.
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.
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/>.
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/
44 DIM=min(find(size(x)>1));
45 if isempty(DIM), DIM=1; end;
51 [y, n] = sumskipnan(log(x),DIM,W);