Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (31 sloc) 638 Bytes
function index=binsearch(x,sval)
% index=binsearch(x,sval)
%
% Binary search for unique values in sorted array.
%
% INPUT:
%
% x Sorted vector of numeric values
% sval Numeric value to be searched in x
%
% OUTPUT:
%
% index index of sval with respect to x
%
% Last modified by fjsimons-at-alum.mit.edu, 18.08.2006
% (C) M. Khan mak2000sw@yahoo.com www.geocities.com/mak2000sw/
index=[];
from=1;
to=length(x);
while from<=to
mid=round((from + to)/2);
dff=x(mid)-sval;
if dff==0
index=mid;
return
elseif dff<0
from=mid+1;
else
to=mid-1;
end
end
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.