Find mean value of grid cells found within a coarser grid cell

조회 수: 5 (최근 30일)
mashtine
mashtine 2016년 5월 1일
답변: Chad Greene 2016년 5월 2일
Hello,
I have two grid, one that is 121x97 (lat_1 & lon_1 in the attached data) and the other is 6x7 (coarser grid, lat_2 & lon_2 in the attached data). I have attached the longitudes and latitudes of the grid cells here. I am trying to find a method (fairly uncomplicated) to find exactly which grid cells of the finer grid are found in each of the coarser grids. I would then like to find their means so that the finer grid now becomes a 6x7 matrix of means from the finer grid.
I am not sure how to use the lat and lon values to find the means. For instance, if one of the coarse grid cells overlaps over 30 finer grid cells, I would like to get the mean of those 30 grid cells.
Hope this makes sense.

답변 (2개)

Image Analyst
Image Analyst 2016년 5월 1일
Do you have a digital image, and can you somehow map lats and lons to actual rows and columns in the digital image? If you have that, then you can simply use blockproc.
  댓글 수: 4
mashtine
mashtine 2016년 5월 2일
Ah! No wonder your confusion. Sorry about that. I have now attached the data.
Image Analyst
Image Analyst 2016년 5월 2일
lat_1: [97x1 double]
lon_1: [121x1 double]
lat_2: [7x1 double]
lon_2: [6x1 double]
These are all different sizes. How are you plotting or visualizing these? Does it require the mapping toolbox (which I don't have)?

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


Chad Greene
Chad Greene 2016년 5월 2일
I think this does what you want:
% Load sample data and create a sample Z1:
load sample_data
Z1 = round(100*(cosd((1:length(lat_1))'))*cosd(1:length(lon_1)));
% Get rows and columns:
r = interp1(lat_2,1:numel(lat_2),lat_1,'nearest','extrap');
c = interp1(lon_2,1:numel(lon_2),lon_1,'nearest','extrap');
[cg,rg] = meshgrid(c,r);
% Create a downsampled version of Z1 with accumarray:
Z1ds = accumarray([rg(:) cg(:)],Z1(:),[length(lat_2) length(lon_2)],@mean,NaN);
% Plot Z1 and downsampled Z1:
figure
subplot(1,2,1)
imagesc(lon_1,lat_1,Z1)
axis xy
subplot(1,2,2)
imagesc(lon_2,lat_2,Z1ds)
axis xy

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by