X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fnan-2.5.5%2Fzscore.m;fp=octave_packages%2Fnan-2.5.5%2Fzscore.m;h=cf19b278e46e2d97724c2699dd81553bc70af883;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/nan-2.5.5/zscore.m b/octave_packages/nan-2.5.5/zscore.m new file mode 100644 index 0000000..cf19b27 --- /dev/null +++ b/octave_packages/nan-2.5.5/zscore.m @@ -0,0 +1,64 @@ +function [i,v,m] = zscore(i,DIM) +% ZSCORE removes the mean and normalizes the data +% to a variance of 1. Can be used for Pre-Whitening of the data, too. +% +% [z,r,m] = zscore(x,DIM) +% z z-score of x along dimension DIM +% r is the inverse of the standard deviation +% m is the mean of x +% +% The data x can be reconstrated with +% x = z*diag(1./r) + repmat(m,size(z)./size(m)) +% z = x*diag(r) - repmat(m.*v,size(z)./size(m)) +% +% DIM dimension +% 1: STATS of columns +% 2: STATS of rows +% default or []: first DIMENSION, with more than 1 element +% +% see also: SUMSKIPNAN, MEAN, STD, DETREND +% +% REFERENCE(S): +% [1] http://mathworld.wolfram.com/z-Score.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 2 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: zscore.m 8223 2011-04-20 09:16:06Z schloegl $ +% Copyright (C) 2000-2003,2009 by Alois Schloegl +% This function is part of the NaN-toolbox +% http://pub.ist.ac.at/~schloegl/matlab/NaN/ + + +if any(size(i)==0); return; end; + +if nargin<2 + DIM=[]; +end +if nargin<3 + W = []; +end +if isempty(DIM), + DIM=min(find(size(i)>1)); + if isempty(DIM), DIM=1; end; +end; + + +% pre-whitening +m = mean(i,DIM,W); +i = i-repmat(m,size(i)./size(m)); % remove mean +v = 1./sqrt(mean(i.^2,DIM,W)); +i = i.*repmat(v,size(i)./size(v)); % scale to var=1 + + \ No newline at end of file