Code running multiple times for different elements of a matrix

1 visualización (últimos 30 días)
Andreas S
Andreas S el 9 de Oct. de 2020
Comentada: Matt J el 10 de Oct. de 2020
Hi everyone. I need some help to code this problem:
The data is 480x10 matrix(ret). I want to calculate the mean of each column from the past 120 elements of the same column
m1=mean(ret(1:120,1:10))
m2=mean(ret(2:121,1:10))
...
m360=mean(ret(360:480,1:10))
How can i do it with a loop and receive the results in a matrix 360x10.
  1 comentario
Matt J
Matt J el 9 de Oct. de 2020
I think you mean,
m360=mean(ret(360:479,1:10))
m361=mean(ret(361:480,1:10))

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 9 de Oct. de 2020
Editada: Matt J el 9 de Oct. de 2020
m=conv2(ret,ones(120,1)/120,'valid')
  2 comentarios
Andreas S
Andreas S el 10 de Oct. de 2020
Thank you very much! It worked for me.
Matt J
Matt J el 10 de Oct. de 2020
You're welcome, but please Accept-click the answer to certify that it worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by