annotate toolboxes/FullBNT-1.0.7/KPMstats/standardize.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [S, mu, sigma2] = standardize(M, mu, sigma2)
wolffd@0 2 % function S = standardize(M, mu, sigma2)
wolffd@0 3 % Make each column of M be zero mean, std 1.
wolffd@0 4 % Thus each row is scaled separately.
wolffd@0 5 %
wolffd@0 6 % If mu, sigma2 are omitted, they are computed from M
wolffd@0 7
wolffd@0 8 M = double(M);
wolffd@0 9 if nargin < 2
wolffd@0 10 mu = mean(M,2);
wolffd@0 11 sigma2 = std(M,0,2);
wolffd@0 12 sigma2 = sigma2 + eps*(sigma2==0);
wolffd@0 13 end
wolffd@0 14
wolffd@0 15 [nrows ncols] = size(M);
wolffd@0 16 S = M - repmat(mu(:), [1 ncols]);
wolffd@0 17 S = S ./ repmat(sigma2, [1 ncols]);
wolffd@0 18