Delete points after a certian i>
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 8 Gen 2016
If you have R2014b or later, use animatedline()
2 Commenti
Walter Roberson
il 9 Gen 2016
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
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!