Delete points after a certian i>
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm trying to simulate an object orbiting another object. As by now I've made a plot where the position of the object gets updated for every step with a changing acceleration/velocity in order to change the direction of it (I hope it makes sense; the code is below):
while i<1000
a_1 = G*M/sqrt(x_p1^2+y_p1^2).*direction_p1; %acceleration
v0_1 = v0_1+h.*a_1; %velocity being updated with step_size h times acc.
x_p1 = x_p1+dt*v0_1(1); y_p1 = y_p1+dt*v0_1(2); % x- og y-position
plot(x_p1,y_p1,'r.')
end
Currently it just makes a lot of points which stays there, so that after a couple of orbits, the points are all one big mess placed on top of each other.

Is there a way so that after, let's say, 15 points have been placed the first placed points will start to get deleted so only 15 points will be visible at the time?
(If you can imagine it look like a trail of points after each other with the motion)
I've tried writing something like
if i>10
delete(x_p1(i-10))
end
but then the simulation just stops after i>10. Any ideas on how I can do it?
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 1월 8일
If you have R2014b or later, use animatedline()
댓글 수: 2
Walter Roberson
2016년 1월 9일
an_line = animatedline('MaxinumNumPoints', 15, 'LineStyle', 'none', 'Marker', '.', 'Color', 'r');
while i<1000
a_1 = G*M/sqrt(x_p1^2+y_p1^2).*direction_p1; %acceleration
v0_1 = v0_1+h.*a_1; %velocity being updated with step_size h times acc.
x_p1 = x_p1+dt*v0_1(1); y_p1 = y_p1+dt*v0_1(2); % x- og y-position
an_line.addpoint(x_p1 ,y_p1);
drawnow();
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!