I have lat, lon, data for a month data, I am working them to put on a regular uniform grid (2 deg) without interpolation (bining). I am getting an error : index exceed dimensions”
I have lat, lon, var are in column matrix, these are obtained from multiple files of 1 month (thousands of rows).Here I am getting an error with X(zind(k,1),zind(k,2))=mean(zind(ind)); where the index exceed dimensions. Thanks for the help,
where x=lat, y=lon, z=var
% make grid for scattered lat, lon, var
data=load('mydata.txt')
x=data(:,1);
y=data(:,2);
z=data(:,3);
%make a grid with 2 degree
cellsize=2;
minx=-90;
maxx=90;
miny=-180;
maxy=180;
xi=(minx:cellsize:maxx);
yi=(miny:cellsize:maxy);
[X,Y]=meshgrid(xi,yi);
[m,n]=size(X);
%populate grid and make average
xind=floor((x-minx)./cellsize)+1;
yind=floor((y-miny)./cellsize)+1;
zind=unique([yind,xind],'rows');
Z=ones(m,n).*NaN;
for k=1:length(zind)
ind=find(xind==zind(k,2)&...
yind==zind(k,1)==1);
X(zind(k,1),zind(k,2))=mean(zind(ind));
end
%make a plot
figure;
axis([-180 180 90 -90]);
imagesc(xi,yi,Z);
**********************
First:
I don’t think the
==1should be there.Second, I think your error comes from the
mean(zind(ind)): You don’t want the mean ofzind, being indices of unique (y,x) indices. You want the mean ofz: