Tiago Silva wrote:
> I have a vector with N elements (where N = a lot) and I want to obtain the sum of each
> set of M adjacent elements.
T = [0 cumsum(TheVector)];
SumEachM = T(M:end)  T(1:endM+1); %I might have an offbyone error here
If, however, the values are such that the cummulative sum could involve significant
loss of precision, then something like:
sum(TheVector(cell2mat(bsxfun(@plus, 0:length(TheVector)M, (1:M).', 'Uniform', 0))),2)
(Sorry, it'd be a nuisance to log in through our firewall layers to crosscheck
that I have everything exactly right.)

.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships  what if we scrambled your data or used Inf, NaN, or complex(rand,rand)?
