1 function cv=coefficient_of_variation(i,DIM)
2 % COEFFICIENT_OF_VARIATION returns STD(X)/MEAN(X)
4 % cv=coefficient_of_variation(x [,DIM])
7 % see also: SUMSKIPNAN, MEAN, STD
10 % http://mathworld.wolfram.com/VariationCoefficient.html
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/
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.
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.
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/>.
32 DIM = find(size(i)>1,1);
33 if isempty(DIM), DIM=1; end;
36 [S,N,SSQ] = sumskipnan(i,DIM);
38 % sqrt((SSQ-S.*S./N)./max(N-1,0))/(S./N); % = std(i)/mean(i)
40 cv = sqrt(SSQ.*N./(S.*S)-1);
42 %if flag_implicit_unbiased_estim,
43 cv = cv.*sqrt(N./max(N-1,0));