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

2 ビュー (過去 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 Center および File ExchangeHistorical Contests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by