Sum up parts of a vector?

2 visualizaciones (últimos 30 días)
Thor
Thor el 24 de En. de 2013
Dear all,
I have a 105120*1 vector and I want to sum up in steps of 288. So I want to have the sum of the first 288 elements, then the sum of the next 288 elements and so, until the end of the vector. So finally I want to have a new vector of the dimension 365*1. So I need finally 365 sums. How can I do that?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 24 de En. de 2013
Editada: Azzi Abdelmalek el 24 de En. de 2013
x=rand(105120,1);
out=sum(reshape(x,288,[]))'
  1 comentario
Thor
Thor el 24 de En. de 2013
Great! Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

Wayne King
Wayne King el 24 de En. de 2013
Editada: Wayne King el 24 de En. de 2013
Something like
k = 1;
stepsize = 288;
for nn = 1:288:105210-stepsize
partsum(k) = sum(vekt(nn:nn+stepsize-1));
k = k+1;
end
That's one possible way. There are many others.
  1 comentario
Thor
Thor el 24 de En. de 2013
Great too! Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by