taking monthly correlation values

1 回表示 (過去 30 日間)
Richard
Richard 2012 年 3 月 6 日
The following example code can be used to calculate the correlation between a data set:
clear all
FieldName = {'loc1','loc2','loc3','loc4'};
data = rand(8760,4);
R = corrcoef(data,'rows','pairwise');
R_Values= [FieldName(nchoosek(1:size(R,1),2)) num2cell(nonzeros(tril(R,-1)))];
Here, 8760 refers to one year worth of data, where a measurement is taken every hour. I'm trying to alter this code to calculate the correlation for every month of the year so that I am left with 12 correlation values for each pair vectors. What would be the best way of doing this?
  2 件のコメント
Kevin Holst
Kevin Holst 2012 年 3 月 6 日
When you say every month of the year, does it have to correspond to the start of calandar months, or can you just take your data and take 12 evenly spaced samples?
Richard
Richard 2012 年 3 月 6 日
The start of the data i.e. the first row corresponds to the first day of the year, so from then on I can just just take 12 evenly spaced samples. So from the first row, every 24 rows would refer to one day... and so on.

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 3 月 6 日
dnew = mat2cell(data,eomday(2011, (1:12))*24,size(data,2));
k = cellfun(@(x)num2cell(nonzeros(tril(corrcoef(x),-1))),dnew','un',0);
out = [FieldName(nchoosek(1:numel(FieldName),2)) [k{:}]];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by