what white arrows means in debugger?
How I finish a recursive function?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alejandro Fernández Guerrero
el 3 de Sept. de 2020
Comentada: Alejandro Fernández Guerrero
el 3 de Sept. de 2020
Hello,
I am really new in matlab programming and I wanted to finish my recursive fuction called partition,
Is a function how find contact points with some conditions implemented in existCP function.
I get the solution of my problen when c(1) == b(1) (STOP CONDITION), but when it should left the partition funcion and export CP as resullt in Recursive function it doesn´t work.
I mean when I run Partition in debugger, the green arrow goes out of partition function but then instead of finish Recursive function the green arrow comes again in Particion(P,X,r,c,b,puntos).
function [CP]=Recursive(P,s,r)
n=length(P);
X(1)=0;
for jj = 1:n-1
X(jj+1)=X(jj)+s;
end
a=[X(1),P(1)];
b=[X(end),P(end)];
points=a;
CP=Particion(P,X,r,a,b,points);
end
function [CP] = Particion(P,X,r,a,b,points)
while 1
[flag,c]=existCP(P,X,r,a,b);
if flag==true
Particion(P,X,r,a,c,points);
else
b=[X(end),P(end)];
if c(1) == b(1)
CP=points;
return
else
points = [points;c];
Particion(P,X,r,c,b,points);
end
end
end
end
Respuestas (1)
Jon
el 3 de Sept. de 2020
In your recursive function there must finally be a branch where you encounter a return.
Once it hits this return, it will back its way up the stack until it finally exits.
If your code never terminates, or hits recursion limit, then somehow your logic must not provide a path for the calculation to finally reach the return statement.
I think the white arrows show where it left the current code and went to the next recursion level.
2 comentarios
Jon
el 3 de Sept. de 2020
If I want to try running your code, what values of P,s and r should I use to demonstrate the issue you are having?
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!