A moving point along a graph.

71 次查看(过去 30 天)
Ian Tee
Ian Tee 2016-4-27
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

回答(2 个)

J. Webster
J. Webster 2016-4-27
编辑:J. Webster 2016-4-27
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 个评论
Ian Tee
Ian Tee 2016-4-28
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)

请先登录,再进行评论。


Xingwang Yong
Xingwang Yong 2020-11-7
Although this is an old thread, in case someone needs,

类别

Help CenterFile Exchange 中查找有关 Networks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by