How to assign a specific values to the nearest X,Y point
조회 수: 4 (최근 30일)
이전 댓글 표시
Dear all,
I have two vectors X and Y which represents the vertices of a delauny triangulation.
Additionally I have two other vectors lat and lon which represents latitude and longitude respectively and are associated to a specific sound speed profile (SSP).
What I need is to obtain a matrix resulting from the assignment of SSP values to the all (X,Y) points taking into account the distances between (X,Y) points and SSP(Longitude,Latitude) .
In fact what I want is to according to the distance between (X,Y) and (Lon,Lat) points assign the SSP value.
Thanks in advance for your help.
댓글 수: 2
Catalytic
2021년 9월 24일
Please combine your attachments into a single .mat file. It is tedious for us to download 5 separate ones.
답변 (1개)
Matt J
2021년 9월 24일
편집: Matt J
2021년 9월 24일
V=interp2(LON,LAT,SSP,X,Y,'nearest');
See also griddedInterpolant.
댓글 수: 5
Matt J
2021년 9월 24일
편집: Matt J
2021년 9월 24일
The A,B,C,D points as you have drawn them are scattered not gridded. However, your attached data appears to be the opposite. You have an SSP data point for every combination of 55 LON coordinates and 48 LAT coordinates. Therefore, your nearest neighbors will be latticed, like below, and your problem becomes equivalent to nearest-neighbor interpolation:
If you did truly have non-gridded SSP values, you could use griddata or scatterdInterpolant instead,
V=griddata(LON,LAT,SSP,X,Y,'nearest');
but that is much less efficient than interp2 when it is applicable.
@Catalytic The L1 and L2 nearest-neighbors are equivalent. Because the neighbors being searched on are vertices of a rectangle surrounding the query point (X,Y), the L1 and L2 distances (or any p-distance) is a separable function of the coordinates and will always yield the same minimum distance point no matter which distance metric is used.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!