Make a point move straight up and down

조회 수: 5 (최근 30일)
SS
SS 2020년 8월 15일
편집: SS 2020년 8월 15일
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

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 8월 15일
Hi,
A simple motion or animation tool with plot tools is drawnow that can be employed in your task, e.g.:
  댓글 수: 2
SS
SS 2020년 8월 15일
편집: SS 2020년 8월 15일
I tried it out and it does not seem to show the up and down motion. Is there something I am missing?
SS
SS 2020년 8월 15일
편집: SS 2020년 8월 15일
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.

댓글을 달려면 로그인하십시오.


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 8월 15일
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
SS
SS 2020년 8월 15일
편집: SS 2020년 8월 15일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by