X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fnan-2.5.5%2Fstd.m;fp=octave_packages%2Fnan-2.5.5%2Fstd.m;h=b1998216debc6fb7769215e497aaf9dba1140288;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05
diff --git a/octave_packages/nan-2.5.5/std.m b/octave_packages/nan-2.5.5/std.m
new file mode 100644
index 0000000..b199821
--- /dev/null
+++ b/octave_packages/nan-2.5.5/std.m
@@ -0,0 +1,124 @@
+function [o,v]=std(x,opt,DIM,W)
+% STD calculates the standard deviation.
+%
+% [y,v] = std(x [, opt[, DIM [, W]]])
+%
+% opt option
+% 0: normalizes with N-1 [default]
+% provides the square root of best unbiased estimator of the variance
+% 1: normalizes with N,
+% this provides the square root of the second moment around the mean
+% otherwise:
+% best unbiased estimator of the standard deviation (see [1])
+%
+% DIM dimension
+% N STD of N-th dimension
+% default or []: first DIMENSION, with more than 1 element
+% W weights to compute weighted s.d. (default: [])
+% if W=[], all weights are 1.
+% number of elements in W must match size(x,DIM)
+%
+% y estimated standard deviation
+%
+% features:
+% - provides an unbiased estimation of the S.D.
+% - can deal with NaN's (missing values)
+% - weighting of data
+% - dimension argument also in Octave
+% - compatible to Matlab and Octave
+%
+% see also: RMS, SUMSKIPNAN, MEAN, VAR, MEANSQ,
+%
+%
+% References(s):
+% [1] http://mathworld.wolfram.com/StandardDeviationDistribution.html
+
+
+% This program is free software; you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation; either version 3 of the License, or
+% (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with this program; If not, see .
+
+% $Id: std.m 8223 2011-04-20 09:16:06Z schloegl $
+% Copyright (C) 2000-2003,2006,2009,2010 by Alois Schloegl
+% This is part of the NaN-toolbox for Octave and Matlab
+% http://pub.ist.ac.at/~schloegl/matlab/NaN/
+
+if nargin<4,
+ W = [];
+end;
+if nargin<3,
+ DIM = [];
+end;
+if isempty(DIM),
+ DIM = find(size(x)>1,1);
+ if isempty(DIM), DIM=1; end;
+end;
+
+
+[y,n,ssq] = sumskipnan(x,DIM,W);
+if all(ssq(:).*n(:) > 2*(y(:).^2))
+ %% rounding error is neglectable
+ y = ssq - y.*y./n;
+else
+ %% rounding error is not neglectable
+ szx = size(x);
+ szy = size(y);
+ if length(szy)1,
+ v = y.*((max(n-1,0)./(n.*n))-1./(n.*ib.*ib)); % variance of the estimated S.D. ??? needs further checks
+end;
+
+