Clear Filters
Clear Filters

Sine function to calculate y position

7 views (last 30 days)
SS on 21 Aug 2020
Answered: Rajani Mishra on 28 Aug 2020
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
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

Answers (1)

Rajani Mishra
Rajani Mishra on 28 Aug 2020
Replace line
plot(x,y, px, py,'o');
this will display just a point rather than the entire sine wave. Also you can refer to below link :


Community Treasure Hunt

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

Start Hunting!