Try this
x = [0.1, 0.2, 0.4, 0.5, 0.4, 0.6, 0.6, 0.6, 0.2, 0.3];
n = numel(x);
k = 5;
if round(n/k)==n/k
split = mat2cell(x, 1, repmat(k, 1, floor(numel(x)/k)));
else
split = mat2cell(x, 1, [repmat(k, 1, floor(numel(x)/k)) mod(n, k)]);
end
helpFun = @(x) {fliplr(cumsum(fliplr(x))./(1:numel(x)))};
split_mean = cellfun(helpFun, split);
split_mean = [split_mean{:}]
Best Answer