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.

回答(1 个)

Matt J
Matt J 2021-9-24
编辑:Matt J 2021-9-24
V=interp2(LON,LAT,SSP,X,Y,'nearest');
See also griddedInterpolant.
  5 个评论
Ricardo Duarte
Ricardo Duarte 2021-9-24
Maybe I'm messing this up but I not sure that this solution gives me the result I want.
Consider the following figure:
I have my (X,Y) point and I have four other areas (A,B,C and D squares) here the ssp was calculated. What I want is to evaluate the distance between my (X,Y) point to the A,B,C and D squares and choose only the square that is closer to (X,Y) and then use the SSP of that square.
For example, in this case, I would choose the B square and discard the others. Then I would change the location of (X,Y) and to the same procedure.
Thank you.
Matt J
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 CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by