필터 지우기
필터 지우기

correlation of an array

조회 수: 5 (최근 30일)
Raman
Raman 2013년 4월 8일
i've an array in which i've stored different matrices. i want to calculate the correlation between the matrices stored in an array
like:
A=[ 12 23 12 34 21 32 43 65 65 76 1 23 43 21 54 98 ]
21 43 2 13 76 87 34 22 89 67 45 88 55 77 54 65
32 45 56 78 89 87 84 54 22 33 43 54 78 98 97 65
67 54 33 44 88 77 66 54 21 15 16 48 90 80 21 66
like if i've array=[A;B;C;D]
i want the correlation between A and B
correlation between A and C
correlation between A and D
correlation between B and C
correlation between B and D
correlation between C and D
help me in doing so
  댓글 수: 2
Tobias
Tobias 2013년 4월 8일
Isn't that basicly the xcorr function? I have not worked with that before, but did you check Cross-correlation?
Raman
Raman 2013년 4월 8일
xcorr2 is fine but how make a loop on it so that it can calculate all the above combination which mentioned above....
for k1=1:length(A)
A1=A(k1)
for k2=k1:length(A)
A2=A(k2)
correlation=xcorr2(k1,k2);
fprintf('%d',correlation);
end
end
the above code calculates the correlation in only one matrix i'e correlation between one pixel and the second pixel in the same matrix... i want to calculate correlation between the different matrix as the combination i've given above...

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2013년 4월 8일
Extract the 4 submatrices and correlate all the permutations.
A = fullMatrix(:, 1:4);
B = fullMatrix(:, 5:8);
C = fullMatrix(:, 9:12);
D = fullMatrix(:, 13:16);
% Now correlate:
AB = xcorr2(A, B);
AC = xcorr2(A, C);
AD = xcorr2(A, D);
BC = xcorr2(B, C);
BD = xcorr2(B, D);
CD = xcorr2(C, D);
There is no need for complicated loops when you have this few matrices, and just a few simple lines of code will do it for you.
  댓글 수: 8
Raman
Raman 2013년 4월 9일
편집: Raman 2013년 4월 9일
ok then what should i do to store oneBlock in an array so that i can calculate the correlation between the matrices...
12 34 56 78
56 78 89 21
66 43 22 32
23 43 76 89
the code i wrote caculates
correlation between 12 and 56
correlation between 12 and 66
correlation between 12 and 23
correlation between 56 and 66
correlation between 56 and 23
correlation between 66 and 23
this i dont want...
i want it to calculate correlation like this if
12 37 56 78 34 99 11 21
56 78 89 21 10 40 89 90
66 43 22 32 45 43 22 55
23 43 76 89 56 44 23 22
i want to calculate
correlation between 12 and 34
correlation between 37 and 99
correlation between 56 and 11
correlation between 78 and 21
correlation between 56 and 10
correlation between 78 and 40
and so on......
i.e correlation between first element of matrice 1 and matrix 2, then second element of matrix 1 and matrix 2 and so on..... how can i acheive this sir?
help me to do so...
Image Analyst
Image Analyst 2013년 4월 9일
I don't understand - those look like pixel values, not ID numbers of blocks. I thought you just had 16 blocks and each block was a 4 by 4 array. You wouldn't compute correlation of single pixel values - you do it with 2D arrays. But frankly I don't know what you're after since you didn't give us the whole picture, the larger context, so I don't know if your approach is even correct to do what you think you want to do, or not.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by