A moving point along a graph.

61 views (last 30 days)
Ian Tee
Ian Tee on 27 Apr 2016
Answered: Xingwang Yong on 7 Nov 2020
Hello everyone, i succesfully plotted a graph that looks like this. figure 1- Graph
Right now, i want to make a point move along the graph. I need some help with that, is there a simple way of making a point move along the plot?
Any help, suggestions or advice will be heavily appreaciated :D

Answers (2)

J. Webster
J. Webster on 27 Apr 2016
Edited: J. Webster on 27 Apr 2016
You put the plot inside of a loop and update the position of the point each time...
x = 0:.01:6;
y = sin(x);
px = 0;
py = 0;
for i=1:100
figure(100); %This is so it will replot over the previous figure, and not make a new one.
plot(x,y, px, py,'o');
pause(0.1);
px = px+6/100;
py = sin(px);
end
  1 Comment
Ian Tee
Ian Tee on 28 Apr 2016
I see, i get the rough idea but i dont know how to update each plot in my case. Any more pointers will be much appreciated :)
% Symbols needed for equation of motion and constants
h0 = 10; % initial height
v0 = 0; % initial velocity
t0 = 0; % Start time
dT = 0.01; %rate of change of time, step size
Tend = sqrt(h0)*2; %time when balls stop bounce
g = -9.81; % Constant, gravity
Friction = 0.4; %To allow dampening, value chosen from trial and error
Time=t0:dT:Tend; %Start time to end time with step size of 1/1000
Height = size(Time);
%Iteration of dx to simulate drop using equation of motion
%eq (1) : x=x+v+1/2*g*t
for iX= 1:length(Time)
H1= h0 + (v0*dT) + (g*dT^2*0.5)*dT; %equation of motion (1)
v0=v0+g*dT; % step size for the change of velocity with time
%disp(H1)
%disp(v0)
%used to predict graph
if H1<0 ;
H1=0; %ball hits ground
v0=-v0*sqrt(Friction); % 'refresh' size of curve to simulate lost of energy
end
Height(iX)=H1; %index of height for each value of time
h0=H1;%couple with friction to start smaller curve with lower new Height
end
plot(Time,Height)

Sign in to comment.


Xingwang Yong
Xingwang Yong on 7 Nov 2020
Although this is an old thread, in case someone needs,

Categories

Find more on Networks 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!