view general/numerical/meanlastdims.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents e44f49929e56
children
line wrap: on
line source
function x=meanlastdims(x,n)
% meanlastdims - compute average over last n dimensions of multidim array
%
% Usage: y=meanlastdims(x,n)
%
% If size1(x) = [m(1) m(2) ... m(k)], then size1(y) = [m(1) ... m(k-n)]
% MEANLASTDIMS ignores any trailing singleton dimensions including 2nd
% dimension of a column vector.

sz=size1(x);
for d=length(sz)-(0:n-1);
	x=sum(x,d)/sz(d);
end