function [avg,sd,range] = stats(x)
% Returns the average (mean), standard deviation
% and range of input vector x
% sd should be same as as std(x,1) 
N=length(x);
avg=sum(x)/N;     % Matlab-function std "normalizes by N-1"
%  std(x,1) normalizes by N and gives the same result as here.
sd = sqrt(sum((x - avg).^2)/N);
range=[min(x),max(x)];
