Make a point move straight up and down

4 visualizaciones (últimos 30 días)
SS
SS el 15 de Ag. de 2020
Editada: SS el 15 de Ag. de 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

Respuestas (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 15 de Ag. de 2020
Hi,
A simple motion or animation tool with plot tools is drawnow that can be employed in your task, e.g.:
  2 comentarios
SS
SS el 15 de Ag. de 2020
Editada: SS el 15 de Ag. de 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 el 15 de Ag. de 2020
Editada: SS el 15 de Ag. de 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.

Iniciar sesión para comentar.


Sulaymon Eshkabilov
Sulaymon Eshkabilov el 15 de Ag. de 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 comentario
SS
SS el 15 de Ag. de 2020
Editada: SS el 15 de Ag. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by