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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by