Binary search in the style of numpy's searchsorted
You are now following this Submission
- You will see updates in your followed content feed
- You may receive emails, depending on your communication preferences
Finds indices in sorted vector x where values would be inserted to maintain sorted order: in style of numpy searchsorted.
indices = searchsorted(x, values)
name value arguments (nv):
'side' (default: 'left')
e.g., side='left': x = [1, 3, 5, 5, 7], values = [2, 5, 7] -> indices = [2, 3, 5]
side='right': x = [1, 3, 5, 5, 7], values = [2, 5, 7] -> indices = [2, 4, 5]
'sortfirst' (default: false)
if true, x will be sorted prior to the search.
Credit: DrGar
(https://stackoverflow.com/questions/20166847/faster-version-of-find-for-sorted-vectors-matlab)
Amended by Luke Jenkins, Apr 2024
Cite As
Luke Jenkins (2026). searchsorted (https://se.mathworks.com/matlabcentral/fileexchange/163511-searchsorted), MATLAB Central File Exchange. Retrieved .
General Information
- Version 1.0.0 (2.01 KB)
MATLAB Release Compatibility
- Compatible with any release
Platform Compatibility
- Windows
- macOS
- Linux
| Version | Published | Release Notes | Action |
|---|---|---|---|
| 1.0.0 |
