for-end loop with increment and movie
2 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
Sean de Wolski
on 10 May 2012
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.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!