how to count the total number of recursion ?
Mostrar comentarios más antiguos
Hello
I have a function
function [out num] = collatz(val)
num = 0;
if val == 1
out = 1;
elseif mod(val, 2) == 0
out = collatz(val/2);
else
out= collatz(3*val+1);
end
k = num + 1;
num = [num k]
end
For the number of counts, num I keep getting num = [0 1] How do I count the total number of recursion that occurs? I heard that we can make a helper function but I have no idea how to make one. Thank you.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming Utilities en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!