]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/harmmean.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / harmmean.m
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.
4
5 %       y = harmmean(x [,DIM [,W]]) is the same as 
6 %       y = mean(x,'H' [,DIM [,W]]) 
7 %
8 % DIM   dimension
9 %       1 STD of columns
10 %       2 STD of rows
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) 
15 %
16 % features:
17 % - can deal with NaN's (missing values)
18 % - weighting of data 
19 % - dimension argument also in Octave
20 % - compatible to Matlab and Octave
21 %
22 % see also: SUMSKIPNAN, MEAN, GEOMEAN
23 %
24
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.
29 %
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.
34 %
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/>.
37
38
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/
43
44
45
46 if nargin<2
47         DIM=min(find(size(x)>1));
48         if isempty(DIM), DIM=1; end;
49 end;
50 if nargin<3
51         W = [];
52 end;
53
54 [y, n] = sumskipnan(1./x,DIM,W);
55 y = n./y;
56