correlation coefficient between cells

2 ビュー (過去 30 日間)
Richard
Richard 2012 年 4 月 3 日
I have a dataset stored in a similar manner to the follwing example:
clear all
Year = cell(1,4);
Year{1} = {'Y2007','Y2008','Y2009','Y2010','Y2011'};
Year{2} = {'Y2005','Y2006','Y2007','Y2008','Y2009'};
Year{3} = {'Y2009','Y2010','Y2011'};
Year{4} = {'Y2007','Y2008','Y2009','Y2010','Y2011'};
data = cell(1,4);
data{1} = {rand(26,1),rand(26,1),rand(26,1),rand(26,1),rand(26,1)};
data{2} = {rand(26,1),rand(26,1),rand(26,1),rand(26,1),rand(26,1)};
data{3} = {rand(26,1),rand(26,1),rand(26,1)};
data{4} = {rand(26,1),rand(26,1),rand(26,1),rand(26,1),rand(26,1)};
Where each cell in 'Year' represents the time where each measurement in 'data' was collected. For example, the first cell in Year ('Year{1}') contains the year where each measurements in 'data{1}' was collected so that data{1}{1} was collected in 'Y2007', data{1}{2} in 'Y2008'...and so on
I am now trying to find the correlation between each measurement with the corresponding (same year) measurement from the other locations. For example for the year 'Y2007' I would like to find the correlation between data{1}{1} and data{2}{3}, then data{1}{1} and data{4}{1}, and then data{2}{3} and data{4}{1} and so on for the remaining years, basically every possible combination of the years.
I know that the corrcoef command should be used to calculate the correlation, but I cannot seem to get to the stage where this is possible. Any advice would be much appreciated.
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 4 月 3 日
Are data always the same length?
Richard
Richard 2012 年 4 月 3 日
Yes all the same length.

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

回答 (1 件)

owr
owr 2012 年 4 月 3 日
Something like this will help you find the index of where 'Y2007' shows in each cell of "Year":
K>> find( strcmp(Year{1},'Y2007') )
ans =
1
K>> find( strcmp(Year{2},'Y2007') )
ans =
3
Use these indicies to get the appropriate vecotrs out of "Data". Throw this in a loop over the unique values of Year and you should be all set:
unique([Year{:}])
ans =
'Y2005' 'Y2006' 'Y2007' 'Y2008' 'Y2009' 'Y2010' 'Y2011'

カテゴリ

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