Running correlations between two matrices

조회 수: 1 (최근 30일)
Allie
Allie 2019년 1월 30일
답변: Allie 2019년 1월 30일
I have two 982x10,000 matrices (matrix A and B). I would like to calculate 60 year running correlations between corresponding columns (e.g. A(1) and B(1), A(2) and B(2), etc.). I can easily do this one at a time using the following code however, I can't find an effective way to apply the running correlation to each successive column.
for i=1:982
z(i,1)=corr(A(i:i+59,1),B(i:i+59,1))
end
I have tried the code below but this produces error messages. What is a good way to do this?
for i=1:982
z(i,:)=corr(A(i:i+59,:),B(i:i+59,:));
end

채택된 답변

Kevin Phung
Kevin Phung 2019년 1월 30일
Have you tried adding another forloop for the columns?
for i=1:982
for j = 1:10000
z(i,1)=corr(A(i:i+59,j),B(i:i+59,j))
end
I dont know what corr() returns, so you might have to adjust your z() output.
Also, your row indices are going to go out of bound. for example, at max i = 982,
you will be looking at rows 982:982+59 for your A and b matrices (which do not exist)

추가 답변 (1개)

Allie
Allie 2019년 1월 30일
This worked. Thank you

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by