for-end loop with increment and movie
Mostrar comentarios más antiguos
My code plots a route taken based on random numbers and takes frames at intervals of 1000 steps. However the total number of steps won't always be divisible by 1000, is there a way of always plotting the final frame in the set?
here's my code at the moment
for j=1:1000:k
M((j-1)/1000+1) = getframe;
plot(x(1:(j+1)),y(1:(j+1)))
axis equal
if x(j+1)==H1 && y(j+1)==H2
break
end
end
hold off
movie(M)
Respuestas (1)
Sean de Wolski
el 10 de Mayo de 2012
0 votos
First, make sure to use drawnow to refresh the graphics queue between loop iterations.
Second, use the for-loop variable as the index and generate the other values from it (i.e. inverse to what you've done). Then run it from 1-however_many
Third, use min() to saturate the variable at the maximum ends of things so you don't get out of dimension errors. e.g. if j = 100001 and the max you have is 100000, use min(j,10000) so you don't over step the number of elements.
1 comentario
Wendy
el 10 de Mayo de 2012
Categorías
Más información sobre Spreadsheets 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!