]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/coefficient_of_variation.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / coefficient_of_variation.m
1 function cv=coefficient_of_variation(i,DIM)
2 % COEFFICIENT_OF_VARIATION returns STD(X)/MEAN(X)
3
4 % cv=coefficient_of_variation(x [,DIM])
5 %  cv=std(x)/mean(x) 
6 %
7 % see also: SUMSKIPNAN, MEAN, STD
8 %
9 %   REFERENCE(S):
10 %   http://mathworld.wolfram.com/VariationCoefficient.html
11
12 %       $Id: coefficient_of_variation.m 8223 2011-04-20 09:16:06Z schloegl $
13 %       Copyright (C) 1997-2003 by Alois Schloegl <alois.schloegl@gmail.com>    
14 %       This function is part of the NaN-toolbox
15 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
16
17 %    This program is free software; you can redistribute it and/or modify
18 %    it under the terms of the GNU General Public License as published by
19 %    the Free Software Foundation; either version 2 of the License, or
20 %    (at your option) any later version.
21 %
22 %    This program is distributed in the hope that it will be useful,
23 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
24 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 %    GNU General Public License for more details.
26 %
27 %    You should have received a copy of the GNU General Public License
28 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
29
30
31 if nargin<2,
32         DIM = find(size(i)>1,1);
33         if isempty(DIM), DIM=1; end;
34 end;
35
36 [S,N,SSQ] = sumskipnan(i,DIM);
37
38 % sqrt((SSQ-S.*S./N)./max(N-1,0))/(S./N);    % = std(i)/mean(i)
39
40 cv = sqrt(SSQ.*N./(S.*S)-1);
41
42 %if flag_implicit_unbiased_estim,
43         cv = cv.*sqrt(N./max(N-1,0));
44 %end;