Sine function to calculate y position

조회 수: 1 (최근 30일)
SS
SS 2020년 8월 21일
답변: Rajani Mishra 2020년 8월 28일
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

답변 (1개)

Rajani Mishra
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 :

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by