Correlation Coefficient of two 3-D matrices
6 次查看(过去 30 天)
显示 更早的评论
I have two matrices, lon x lat x time [288 142 21]. How can I find the correlation coefficient at each grid point and plot the results?
0 个评论
采纳的回答
Daniele Mascali
2021-3-18
Considering A and B your two matrices, you could use the following code:
%reshape each matrix
SIZE = size(A);
A_2d = reshape(A,[SIZE(1)*SIZE(2),SIZE(3)]);
B_2d = reshape(B,[SIZE(1)*SIZE(2),SIZE(3)]);
% Calculate Pearson's correlation. It can be easily computed by transoforming data
% to zero mean and unit standard deviation (i.e., zscore). Then it is just a dot product.
A_2d_z = zscore(A_2d');
B_2d_z = zscore(B_2d');
correlation_1d = sum(A_2d_z.*B_2d_z)/(SIZE(3)-1);
%reshape back to the original size
correlation_2d = reshape(correlation_1d,[SIZE(1),SIZE(2)]);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!