Make a point move straight up and down

9 vues (au cours des 30 derniers jours)
SS
SS le 15 Août 2020
Modifié(e) : SS le 15 Août 2020
Hi,
I would like to know how to plot a point and just make it go up, down, and back to the starting point. I was thinking about making a list of y values but was not sure if there was a simpler way.
Thanks

Réponses (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 15 Août 2020
Hi,
A simple motion or animation tool with plot tools is drawnow that can be employed in your task, e.g.:
  2 commentaires
SS
SS le 15 Août 2020
Modifié(e) : SS le 15 Août 2020
I tried it out and it does not seem to show the up and down motion. Is there something I am missing?
SS
SS le 15 Août 2020
Modifié(e) : SS le 15 Août 2020
x = 0:.01:50; %linspace of x
y = sin(x); %wave equation
px = 0; %initial x plot
py = 0; %initial y plot
for i=1:1000 %loop
set(gcf,'DoubleBuffer', 'on');
h = patch([0 1 0 1], [0 1 1 0], 'r');
hold on
figure(100); %so code will replot over the previous figure, and not make a new one.
hold off
py = y(i)
plot(x,y, px, py,'o'); %circle point
pause(0.02); %speed of moving point
end
Here is what I have. But when I overlay an image on it, it flickers. I also want to get rid of the sine wave, and just keep the point moving up and down.

Connectez-vous pour commenter.


Sulaymon Eshkabilov
Sulaymon Eshkabilov le 15 Août 2020
Hi,
If I've understood your question correctly, you'd like to get a up and down motion of a point x, y(i). Then here is one of the possible animated plots with drawnow:
for ii=1:numel(x) %loop
plot(x,y, '--', px, y(ii),'o', 'markerfacecolor', 'y'); %circle point
hold off
drawnow
end
  1 commentaire
SS
SS le 15 Août 2020
Modifié(e) : SS le 15 Août 2020
Hi, thank you! that works. However, additionally, I wanted to show the dot moving on a picture that I uploaded, so I want to hide the sine wave and just show the dot. When I add the picture, the whole thing flickers. How would I hide both the wave and prevent the flickering? You can see the code I have in the above comment. I apologize for all the questions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by