function x=binavg(x,n); % function x=binavg(x,n); % % from Gene Terrey's MATLAB course if (n<2), return; end [nr, nc] = size(x); % vector case if (nr==1 | nc==1), nx = fix(max([nr,nc])/n); % dimension of x after decimation y = zeros(n,nx); % columns of y hold points to average y(:) = x(1:n*nx); % truncate leftover points in x x = mean (y); % perform the average if (nc==1) x = x(:); end % make x a column if initially so else % array case nx = fix(nr/n); y = zeros(n,nx*nc); % columns of y hold points to average x = x(1:n*nx,:); % truncate x to an integer # of avg's y(:) = x(:); % resize x into y x = zeros(nx,nc); % make a template for the new size of x x(:) = mean(y).'; % perform the average end