MATLAB: Debugging help for the exponential search code below

expontential search algorithmmatlab function

function [ Ind] = exponSearch(arr, n, x)
if arr(0) == x
currentIndex = 0;
end
i=1;
while i<n && arr(i) <= x
i= i.*2;
Ind = binSearch(V, i/2, min(i,n), x);
end
function Cind = binarySearch(V, l, r, x)
if r >= l
mid = ceil(l+(r-l)/2);
if V(mid) == x
end
%if the target is smaller than the middle element
if V(mid) >x
Cind= binSearch(V, l, mid-1,x);
disp(Cind);
end
Cind = binSearch(V,mid+1,r,x);
end
end
end

Best Answer

It does exactly what it does. There is no problem that we can see, since we have no idea what it is supposed to do. Is the goal to return an error message, probably that no function or variable named binSearch exists?
When you have a problem with code, tell us what the error that is returned. Otherwise, we need to guess.
I might point out that there is NO binSearch function provided. Nothing with that name, yet you call it repeatedly. Interestingly, there is a function named binarySearch. Perhaps you were just being lazy. But it would seem this is an obvious flaw, unless of course, you have some code named binSearch somewhere on your search path.