Correlation Coefficient of two 3-D matrices

조회 수: 6 (최근 30일)
Brendan Clark
Brendan Clark 2021년 3월 18일
댓글: Brendan Clark 2021년 3월 18일
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?

채택된 답변

Daniele Mascali
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!

Translated by