A moving point along a graph.

조회 수: 66 (최근 30일)
Ian Tee
Ian Tee 2016년 4월 27일
답변: Xingwang Yong 2020년 11월 7일
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에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by