for-end loop with increment and movie
이전 댓글 표시
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)
답변 (1개)
Sean de Wolski
2012년 5월 10일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!