How to find correlations between a vector and a 3D array and plot the correlations spatially?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Austin M. Weber
il 14 Set 2021
Commentato: Austin M. Weber
il 14 Set 2021
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!
0 Commenti
Risposta accettata
the cyclist
il 14 Set 2021
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Distribution Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!