Hi, all! I have a array of monthly log returns from 1962 to 2016, I wish to extract the monthly values, every 12th value.

조회 수: 1 (최근 30일)
Can andybody assist with this issue? How do I extract every 12th value?
Thanks!
  댓글 수: 1
Ola Sveen
Ola Sveen 2017년 10월 13일
편집: Ola Sveen 2017년 10월 13일
I also wish to take the average of every 12th value. Eg. mean of 1-12, mean 12-24, mean 24 - 36. Anybody?

댓글을 달려면 로그인하십시오.

채택된 답변

KL
KL 2017년 10월 13일
편집: KL 2017년 10월 13일
data = 1:144; %sample data
data_mean = arrayfun(@(a,b) mean(data(a:b)),1:12:numel(data),12:12:numel(data))
  댓글 수: 7
Ola Sveen
Ola Sveen 2017년 10월 16일
KL, i´m sorry for the late reply. Many thanks for your assistance. The task have developed some, and we want to sum every 12th value like you prepose, du you know how this is done?
KL
KL 2017년 10월 17일
To sum every 12 rows, replace "mean" in my answer with "sum".

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ola Sveen
Ola Sveen 2017년 10월 13일
편집: Ola Sveen 2017년 10월 13일
Thx KL!
Now I would like to extract annual log returns from a dataset containing prices and dates. Do you know how to solve this? I have calculated the monthly log returns, how do I calculate the annual. I guess I need some sort of loop function, taken in consideration the formula for log return.
many thanks

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by