Find the id of the closest value in an array to a given value

버전 1.0.0.0 (2.75 KB) 작성자: David J. Mack
Returns the index of the closest value in an array X to given values Y
다운로드 수: 78
업데이트 날짜: 2016/9/14

라이선스 보기

For given column vector X and some values Y, FINDCLOSESTID2VAL returns the indices in X which are closest to Y, e.g.: FINDCLOSESTID2VAL([0.1 -1 -0.05 10],0) will return 3, since -0.05 is the closest value to 0.
This function is very handy for time series, where you want to get the id of a time point which might not be exactly matched.
This function is very fast for small to moderate sized 'X' and small 'Vals'. For a function doing the same work quickly on two very large arrays and with some additional features see NEARESTPOINT by Jos:
www.mathworks.com/matlabcentral/fileexchange/8939
The figure on the upper left shows the max. length of 'Vals' versus the length of 'X' for which FINDCLOSESTID2VAL (f1) will be faster than NEARESTPOINT (f2) including the equation to compute the critical value for arbitrary lengths of 'X'.

인용 양식

David J. Mack (2024). Find the id of the closest value in an array to a given value (https://www.mathworks.com/matlabcentral/fileexchange/59043-find-the-id-of-the-closest-value-in-an-array-to-a-given-value), MATLAB Central File Exchange. 검색됨 .

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

받음: nearestpoint(x, y, m)

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.0

Linked to NEARESTPOINT.
Added speed test for FINDCLOSESTID2VAL vs. NEARESTPOINT to the FEX description.