Sine function to calculate y position
4 views (last 30 days)
Show older comments
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
h = patch([0 1 0 1], [0 1 1 0], 'r');
figure(100);%so code will replot over the previous figure, and not make a new one.
py = y(i)
plot(x,y, px, py,'o'); %circle point
pause(0.05); %speed of moving point
Rajani Mishra on 28 Aug 2020
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 :
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!