Make a point move straight up and down

3 ビュー (過去 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 Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by