Correlation between spatially averaged gridbox and global gridpoints
Show older comments
An issue I've been having in Matlab as I learn to use it more efficiently has brought up a question about the way things are done.
In the IRIDataLibrary, I can select global Precip data (all gridpoints) and SST data (averaged for Niño 3 region gridboxes), and map their correlation. However, when I export this data to Matlab, the dimensions of each dataset are mismatched, so I cannot perform a manual correlation test. (The reason I want to do the correlation in Matlab is that there seems to be an error in the way Matlab reproduces the IRIDL's correlation contour map for certain seasons.)
What am I doing wrong here? How does the IRIDL reconcile the dimension mismatch but Matlab does not?
My code:
prcp=ncread('http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCEP/.CPC/.Merged_Analysis/.monthly/.latest/.ver2/.prcp_est/T/%281986-2015%29/VALUES/T/monthlyAverage/T/%28Oct-Dec%29/seasonalAverage/dods', 'prcp_est');
SST=ncread('http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NCDC/.ERSST/.version4/.sst/X/-150/-90/RANGEEDGES/Y/-5/5/RANGEEDGES/T/%281986-2015%29/RANGE/T/monthlyAverage/T/%28Oct-Dec%29/seasonalAverage/%5BX/Y%5Daverage/dods', 'sst');
nx=144; ny=72; nt=30; corp=zeros(nx,ny);
for x=1:nx
for y=1:ny
if prcp(x,y,1) ~= nan
[r,p]=corrcoef(prcp(x,y,:),SST);
corp(x,y)=r(1,2);
else
corp(x,y)=nan;
end
end
end
cn = 20; c1 = [255, 0, 0]; c2 = [255, 255, 255]; c3 = [255, 255, 255]; c4 = [0, 0, 255]; cmap=interp1([1,cn/2,cn/2+1,cn],[c4;c3;c2;c1]/255,1:cn);
lat=-5:0.05:5; lon=-150:0.05;-90; [LON LAT]=meshgrid(lon,lat);
figp=corp';
figure(1)
contourf(lon,lat,figp,-1:0.1:1,'linestyle','none')
title('precipitation and time series correlation') hold on
axis([-150 -90 -25 50])
colormap(cmap) colorbar('location','eastoutside')
caxis([-1 1])
Much of this is irrelevant because I receive an 'Line 61' error on 'contourf' function saying "X must match size of Z".
I have done this before just fine with matrices of identical dimensions. Any insight would be wonderful.
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!