nearestpoint(x, y, m)

버전 4.2.0.0 (5.11 KB) 작성자: Jos (10584)
NEARESTPOINT - find the nearest value in another vector
다운로드 수: 7.4K
업데이트 날짜: 2017/12/20

라이선스 보기

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) (2024). nearestpoint(x, y, m) (https://www.mathworks.com/matlabcentral/fileexchange/8939-nearestpoint-x-y-m), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2017b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Spatial Search에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
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