1 function [y] = harmmean(x,DIM,W)
2 % HARMMEAN calculates the harmonic mean of data elements.
3 % The harmonic mean is the inverse of the mean of the inverse elements.
5 % y = harmmean(x [,DIM [,W]]) is the same as
6 % y = mean(x,'H' [,DIM [,W]])
11 % default or []: first DIMENSION, with more than 1 element
12 % W weights to compute weighted mean (default: [])
13 % if W=[], all weights are 1.
14 % number of elements in W must match size(x,DIM)
17 % - can deal with NaN's (missing values)
19 % - dimension argument also in Octave
20 % - compatible to Matlab and Octave
22 % see also: SUMSKIPNAN, MEAN, GEOMEAN
25 % This program is free software; you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation; either version 2 of the License, or
28 % (at your option) any later version.
30 % This program is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
35 % You should have received a copy of the GNU General Public License
36 % along with this program; If not, see <http://www.gnu.org/licenses/>.
39 % $Id: harmmean.m 8223 2011-04-20 09:16:06Z schloegl $
40 % Copyright (C) 2000-2002,2009 by Alois Schloegl <alois.schloegl@gmail.com>
41 % This is part of the NaN-toolbox. For more details see
42 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
47 DIM=min(find(size(x)>1));
48 if isempty(DIM), DIM=1; end;
54 [y, n] = sumskipnan(1./x,DIM,W);