function  [mean, stdev] = stat(x) 
% STAT  Mean and standard deviation 
% For a vector x, stat(x) returns the mean of x; 
% [mean, stdev] = stat(x) both the mean and standard deviation. 
% For a matrix x, stat(x) acts columnwise. 
 [m  n] = size(x); 
 if m == 1 
   m = n;    % handle case of a row vector  
 end 
 mean = sum(x)/m; 
 stdev = sqrt(sum(x.^ 2)/m - mean.^ 2);