Make a point move up and down

7 ビュー (過去 30 日間)
SS
SS 2020 年 8 月 7 日
コメント済み: SS 2020 年 8 月 8 日
I am trying to code for a point inserted on an image that is stationary on the x direction but is moving up and down in the y direction. I have set px = 0 but I am not sure what to do about py.
Here is what I have:
x = 0:.01:20; %linspace of x
y = sin(x); %wave equation
px = 0; %initial x plot
py = 0; %initial y plot
img =imread('AvgBscan.tiff'); %read in image
for i=1:100 %loop
imshow(img);
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
plot(x,y, px, py,'o'); %circle point
pause(0.02); %speed of moving point
px = 0;
py = sin(px); %get that point to move
end

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 7 日
x = 0:.01:20; %linspace of x
y = sin(x); %wave equation
px = 0; %initial x plot
py = 0; %initial y plot
img =imread('AvgBscan.tiff'); %read in image
for i=1:100 %loop
imshow(img);
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
  5 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 8 日
Your loop is to 100 which gets you to x=0+99*0.01 which is 0.99 radians which is not enough to have started moving down again.
SS
SS 2020 年 8 月 8 日
Got it, thank you once again

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by