Counter goes up than down to 1 in recursive function
Mostrar comentarios más antiguos
Hello,
I want my function to return how many 'moving windows' of a particular size can fit in a given length_n-long signal, with a given hop size.
here is my function :
| function N_n = numWindows( N_n, currentSample_n, hopSize_n, length_n, width_n )
% check if we have reached the end of the signal
if currentSample_n + width_n >= length_n
return
else
currentSample_n = currentSample_n + hopSize_n ;
N_n = N_n + 1;
% here we call the same function on the rest of the signal
numWindows( N_n, currentSample_n, hopSize_n, length_n, width_n );
end
return
end|
This code returns systematically N_n = 2; When I entered debug mode I saw that N_n was increasing normally to the correct value, then as the function exited the "if"s one after the other, I saw that N_n was decreasing 1 by 1, just as it had increased in the first place. And the function stopped with N_n = 2.
I tried it with a while loop but it was quickly taking a very long time as the signals started to get long (= big length_n input value).
I would be very grateful to any kind of advice on this problem, thank you very much !
Léo.
4 comentarios
Léonard Roussel
el 4 de Jul. de 2012
Editada: Léonard Roussel
el 4 de Jul. de 2012
AC
el 4 de Jul. de 2012
Nevermind, got it, see answer below.
Léonard Roussel
el 4 de Jul. de 2012
Respuesta aceptada
Más respuestas (1)
Léonard Roussel
el 4 de Jul. de 2012
0 votos
1 comentario
AC
el 4 de Jul. de 2012
Did you try the bit of code I just submitted? It works on my computer. (I think we posted at the same time :))
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!