nearestpoint(x, y, m)

NEARESTPOINT - find the nearest value in another vector

您现在正在关注此提交

NEARESTPOINT - find the nearest value in another vector

IND = NEARESTPOINT(X,Y) finds the value in Y which is the closest to each value in X, so that abs(Xi-Yk) => abs(Xi-Yj) when k is not equal to j.
IND contains the indices of each of these points.
Example:
NEARESTPOINT([1 4 12],[0 3]) -> [1 2 2]
[IND,D] = ... also returns the absolute distances in D,that is D == abs(X - Y(IND))
NEARESTPOINT(X, Y, M) specifies the operation mode M:
1) 'nearest' : default, same as above
2) 'previous': find the points in Y that just precedes a point in X
NEARESTPOINT([1 4 12],[0 3],'previous') -> [1 1 1]
3) 'next' : find the points in Y that directly follow a point in X
NEARESTPOINT([1 4 12],[0 3],'next') -> [2 NaN NaN]

If there is no previous or next point in Y for a point X(i), IND(i)
will be NaN.

X and Y may be unsorted.

This function is quite fast, and especially suited for large arrays with
time data. For instance, X and Y may be the times of two separate events, like simple and complex spike data of a neurophysiological study.
Run NEARESTPOINT('test') to see a test of it's running time

引用格式

Jos (10584) (2026). nearestpoint(x, y, m) (https://ww2.mathworks.cn/matlabcentral/fileexchange/8939-nearestpoint-x-y-m), MATLAB Central File Exchange. 检索时间: .

类别

Help CenterMATLAB Answers 中查找有关 Spatial Search 的更多信息

一般信息

MATLAB 版本兼容性

  • 兼容任何版本

平台兼容性

  • Windows
  • macOS
  • Linux
版本 已发布 发行说明 Action
4.2.0.0

updated for newer NL releases

4.1.0.0

fixed error mentioned by Julian (D was requested but no nearest point was found).

1.1.0.0

Updated function to avoid errors when called with NaNs and empty variables. Thanks Drew.

1.0.0.0

corrected error when using 'prev' option