Daniel@0: function [S, mu, sigma2] = standardize(M, mu, sigma2) Daniel@0: % function S = standardize(M, mu, sigma2) Daniel@0: % Make each column of M be zero mean, std 1. Daniel@0: % Thus each row is scaled separately. Daniel@0: % Daniel@0: % If mu, sigma2 are omitted, they are computed from M Daniel@0: Daniel@0: M = double(M); Daniel@0: if nargin < 2 Daniel@0: mu = mean(M,2); Daniel@0: sigma2 = std(M,0,2); Daniel@0: sigma2 = sigma2 + eps*(sigma2==0); Daniel@0: end Daniel@0: Daniel@0: [nrows ncols] = size(M); Daniel@0: S = M - repmat(mu(:), [1 ncols]); Daniel@0: S = S ./ repmat(sigma2, [1 ncols]); Daniel@0: