How do I compute the correlation between corresponding rows of two matrices?
52 次查看(过去 30 天)
显示 更早的评论
I have two matrices, X and Y, which each have 60 columns and 10,000 rows.
I would like to create a vector R, such that the nth value of vector R represents the correlation between row n of matrix X and row n of matrix Y.
I have tried:
[R,pval] = corr(X',Y');
but this gives me R as a 10,000-by-10,000 matrix.
What am I doing wrong?
0 个评论
采纳的回答
possibility
2018-5-11
X is 10,000-by-60 Y is 10,000-by-60
X' is 60-by-10,000 Y' is 60-by-10,000
By correlating these two matrices, i.e. R=corr(X', Y'), you get the 10,000-by-10,000 R matrix whose elements are the pairwise correlation of each column of X' and Y', that is each row of X and Y.
So, you are doing the right thing! Just check the diagonals of that matrix:
>> Rvec= diag (R)
更多回答(2 个)
Shounak Shastri
2018-5-11
From what I know, Correlation Matrices are usually square. As in you have 10000 rows with 60 elements in each row. So if you take 1 row of dimension 1 x 60, the dimension of your corr matrix would be 60 x 60.
But in your example, you took a transpose. So, now the size of each row is 1 x 10000. And thus when you perform correlation on the rows, you would get a 10000 x 10000 matrix.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!