searchsorted
Version 1.0.0 (2.01 KB) by
Luke Jenkins
Binary search in the style of numpy's searchsorted
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 .
MATLAB Release Compatibility
Created with
R2024a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
