필터 지우기
필터 지우기

How to find correlations between a vector and a 3D array and plot the correlations spatially?

조회 수: 2 (최근 30일)
How can I calculate correlations between a vector of isotope data from a single location and a spatial array of precipiation data? And how can I plot the correlations for visual interpretations?
Here are some fake data:
isotope = rand(1,50)*10; % 1x50 vector of isotopes/year
lat = linspace(1,60,120); % 1x120 vector of latitudes
lon = linspace(120,180,120); % 1x120 vector of longitudes
time = 1901:1950; % 1x50 vector of years
precip = randi(3000,120,120,50); % 120x120x50 array of precipitation/year
Thanks!

채택된 답변

the cyclist
the cyclist 2021년 9월 14일
Is it correct that the result will be a 120x120 array of correlations, where each entry is the correlation of the 50 isotope values (which never change), and the 50 precip values at that location.
And is it also correct that we do not actually need the lat, lon, and time values to calculate that?
If so, then I believe this does what you want. I tried to fully comment the code, so you could more easily understand what is going on.
% Set random number generator seed, for reproducibility
rng default
% The data
isotope = rand(1,50)*10; % 1x50 vector of isotopes/year
lat = linspace(1,60,120); % 1x120 vector of latitudes
lon = linspace(120,180,120); % 1x120 vector of longitudes
time = 1901:1950; % 1x50 vector of years
precip = randi(3000,120,120,50); % 120x120x50 array of precipitation/year
% Preallocate memory for the correlations
r = zeros(120,120);
% Loop over the locations
for xi = 1:120
for yi = 1:120
r_mat = corrcoef(isotope,precip(xi,yi,:)); % This gets all pairwise correlations
r(xi,yi) = r_mat(1,2); % Store only the cross-correlation (at this location)
end
end
% Heatmap of the correlations
figure
imagesc(r)
axis square
  댓글 수: 1
Austin M. Weber
Austin M. Weber 2021년 9월 14일
This is excellent! I appreciate you for leaving comments with explanations. They were very helpful in my understanding. Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by