Debugging help for the exponential search code below

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

 Respuesta aceptada

John D'Errico
John D'Errico el 3 de Mayo de 2017
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.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 3 de Mayo de 2017

Respondida:

el 3 de Mayo de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by