function y = standardize ( x ) 
% function y = standardize ( x ) 
% standardize a vector or a matrix (each column is normalized)

ndim = ndims(x);
nsz = size(x);
if ndim > 2;
  x = reshape(x, nsz(1), prod(nsz(2:ndim)));
end


[m,n]=size(x);
if(m==1) 
  m=n;
end
y = ( x - ones(m,1)*nanmean(x) ) ./ ( ones(m,1)*nanstd(x) );

y = reshape(y, nsz);
