Binary Search for numeric vector

version (2.5 KB) by Dr. Murtaza Khan
Search given value in a sorted vector, returns the index of location where the value is found.


Updated 9 Jul 2009

View License

x: vector of numeric values, x should already be sorted in ascending order
(e.g. 2,7,20,...120)
sval: numeric value to be search in x

index: index of sval with respect to x. If sval is not found in x then index is empty.

Cite As

Dr. Murtaza Khan (2022). Binary Search for numeric vector (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Binary Search

Community Treasure Hunt

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

Start Hunting!