Get averages for different ranges

Hello, I would like to obtain averages for different ranges, for example:
P = mean(data(1:15,:));
P = mean(data(16:31,:));
P = mean(data(32:45,:));
P = mean(data(46:60,:));
P = mean(data(61:75,:));
P = mean(data(76:91,:));
I don't know how to do a loop. The size of the matrix is 91x24.
Thank you for your suggestions and sorry for my bad english.
Lis.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 21 de Mzo. de 2013
for k=1:6
P{k}=mean(data((k-1)*15+1:k*15))
end

3 comentarios

lissette
lissette el 21 de Mzo. de 2013
Thanks for replying. But the ranges are 15, 16 14 15 15 16, not only 15. Help me please.
r=[15,16,14 15 15 16]
ii1=1
for k=1:6
ii2=ii1+r(k)-1
P{k}=mean(data(ii1:ii2,:))
ii1=ii2+1
end
lissette
lissette el 21 de Mzo. de 2013
Thank you very much, works perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda 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