필터 지우기
필터 지우기

Assigning values from small grid into larger grid using nearest coordinates

조회 수: 4 (최근 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