How to compute the correlation between two metrices of same dimenstion (correlation between a column of a matrix to corresponding column of other matrix)?
조회 수: 6 (최근 30일)
이전 댓글 표시
I have two matrix A and B. Both metrics are same dimenstion. I need to compute the correlation coefficient between [A(:,1), B(:,1)], [A(:,2), B(:,2)], ......., [A(:,n),B(:,n)]. It is a column of A to a corresponding a column in B. At the end I want the output like correlation cofficient of each column from A matrix to corresponding column of B matrix. How do I perform efficiently in MATLAB?
댓글 수: 0
채택된 답변
Ive J
2021년 9월 4일
A = rand(10, 3);
B = rand(10, 3);
R = diag(corr(A, B))
댓글 수: 9
Ive J
2021년 9월 6일
The previous one was technically the same. I included this line:
R2 = diag(corr(A, B)); % to compare (you don't need it for your large arrays)
only for you to see my approach does exactly what corr built-in function does, with the difference that it only calculates column-wise correlation coeffs and not all pairwise combinations. So, this is computationally more efficient and thanks to MATLAB, it's done multithreaded.
Glad it worked for you.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!