From: forkandwait w on
Hi

I would like to sum a vector, say [ 1 1 1 2 2 2 ] to get [3 6].

I was thinking of using a matrix like [1 1 1 0 0 0; 0 0 0 1 1 1], but I would like to find a graceful way to create said matrix. Is there a matlab idiom for this?

FYI, I am taking a 110 vector of 1 year age wide fertility rates and collapsing it by groups of 5.

tx
From: Matt Fig on
x = [ 1 1 1 2 2 2 ]
sum(reshape(x,3,2))

Make the appropriate alterations for your problem.
From: forkandwait w on
> x = [ 1 1 1 2 2 2 ]
> sum(reshape(x,3,2))
>
> Make the appropriate alterations for your problem.

Oh duh. Thanks for the advice...