for-end loop with increment and movie
Ältere Kommentare anzeigen
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)
Antworten (1)
Sean de Wolski
am 10 Mai 2012
0 Stimmen
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 Kommentar
Wendy
am 10 Mai 2012
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!