function i = binsearch(array, value) low = 1; high = numel(array); i = 0; while ( low <= high ) mid = floor((low + high)/2); if (array(mid) > value) high = mid - 1; elseif (array(mid) < value) low = mid + 1; else i = mid; return; endif endwhile endfunction