フィルターのクリア

question with correlation

1 回表示 (過去 30 日間)
Mate 2u
Mate 2u 2012 年 5 月 11 日
I have a array of X x Y size.
I need to do correlation of all the columns as combinations. So need to do correlation of each column with other columns and then once I have all the correlations of all combinations, I want to take a average.
Thanks

採用された回答

Richard
Richard 2012 年 5 月 11 日
Not sure what you are asking, but this may help.
a = 1;
b = 20;
data = a + (b-a).*rand(20,4);
R = corrcoef(data);
RPairs = [nchoosek(1:size(data,2),2), nonzeros(tril(R,-1))];
Where data is your matrix, R is the correlation between each pair of columns, and RPairs represents the column numbers in RPairs(:,1:2) and the corresponding correlation coefficient in RPairs(:,3). Then if you want to calculate the average correlation you simply take the mean of the third column:
MeanR = mean(RPairs(:,3))
Hope this helps
  4 件のコメント
Mate 2u
Mate 2u 2012 年 5 月 11 日
Ive percentaged where I need correlation.....this is the full code.
A = [1 2 2 2 1 2 3 4 1 2 2 2 2 1 2 3 4 1 1 1 1]
n=2; %n
x=2;
for i =1:length(A)-n+1
ZZ= strfind(A,A(1:1+n-1));
if (length(ZZ)==1)
C(i)=0;
end
index =1;
for j=1:length(ZZ)
array(:,index) = A(ZZ(j)+n:ZZ(j)+n+x);
%%%%% NEED to do correlation here
index=index+1;
end
end
Mate 2u
Mate 2u 2012 年 5 月 11 日
Error using horzcat
CAT arguments dimensions are not consistent.

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

その他の回答 (1 件)

Mate 2u
Mate 2u 2012 年 5 月 11 日
May I should of rephrased what I meant. When I have a correlation matrix....using corrcoef, how can I take average of the bottom left corner or top right corner?
  1 件のコメント
Richard
Richard 2012 年 5 月 11 日
This can be achieved with the script I provided above.
nonzeros(tril(R,-1))
This will find the lower triangular part of the correlation matrix, or as you say bottom left corner, 'nonzeros' then removes the zeros from the matrix which is created by 'tril' thus genberating a vector of these correlation values. Does this make sense?

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by