Assigning values from small grid into larger grid using nearest coordinates

1 次查看(过去 30 天)
I am trying to assign new values of depth from a smaller cropped grid (480 x 480 - lon, lat, depth) into a larger grid (4800 x 5760 - lon, lat, depth) using the nearest coordinates from both grids.
I have so far found the indexes of latitude and longitude which are within the larger grid, but I am struggling to assign the new bathymetry values at these index points, and keep the bathymetry values the same outside of these index points.
Would anyone be able to help me?
lon_new = unique(lon_smallgrid); % unique longitude values from the small grid (1800 x 1)
lat_new = unique(lat_smallgrid); % unique latitude values from the small grid (1800 x 1)
lon_orig = unique(lon.largegrid); % unique longitude values from the large grid (4800 x 1)
lat_orig = unique(lat.largegrid); % unique latitude values from the large grid (5760 x 1)
[ilon] = nearestpoint(lon_new, lon_orig); % value of lon_new which is closest to each value in lon_orig (1800 x 1)
[ilat] = nearestpoint(lat_new, lat_orig); % value of lat_new which is closest to each value in lat_orig (1800 x 1)

回答(1 个)

KSSV
KSSV 2019-4-16
Read about knnsearch. This will give you indices and you can easily replace the values.
  1 个评论
Charlotte Findlay
Charlotte Findlay 2019-4-16
编辑:Charlotte Findlay 2019-4-16
Hi KSSV,
So knnsearch just gives me the same output as nearestpoint.
I found a way to input the data directly into the larger grid (depth) if the max(ilat/ilon) - min(ilat/ilon) is equal to the size of the small grid (see code below).
depth((min(min(ilon)):max(max(ilon))-1), (min(min(ilat)):max(max(ilat))-1)) = small_grid;
But now I'm stuck again as some of my small grids have different dimensions to the max(ilat/ilon) - min(ilat/ilon).
Does anyone have any ideas how to deal with this?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by