Sine function to calculate y position
1 回表示 (過去 30 日間)
古いコメントを表示
In the code below, I have a circle moving up and down, with the function y = sin(x) serving as the origin. However, I need to fix this so that the sine equation is used to only calculate the y-position of the circle at each point in time. I do not want the entire sine wave plotted. What would be the best way to do this? I was thinking a list? Any help appreciated!
x = 0:.01:50; %linspace of x
y = sin(x); %wave equation
px = 10; %initial x plot
py = 0; %initial y plot
img =imread('AvgBscan.tiff'); %read in image
for i=1:630 %loop
imshow(img);
set(gcf,'DoubleBuffer', 'off');
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.05); %speed of moving point
drawnow
end
0 件のコメント
回答 (1 件)
Rajani Mishra
2020 年 8 月 28 日
Replace line
plot(x,y, px, py,'o');
with
plot(px,py,'o');
this will display just a point rather than the entire sine wave. Also you can refer to below link :
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!