plotting in time domain - update plot

1 次查看(过去 30 天)
Richard
Richard 2012-12-9
I'm working through an example I saw online concerning vertical motion under gravity. The following code and plot shows the outcome:
% Vertical motion under gravity example
g = 9.81;
u = 60;
t = 0:0.1:12.3; % time in seconds
for i = 1:length(t);
s = (u.*t(i))-(g.*t(i).^2)./ 2;
plot(t(i),s);
xlim([0 14]);
ylim([0 200]);
hold on;
drawnow
title('Vertical motion under gravity');
xlabel('time');
ylabel('vertical displacement');
end
Is it possible to alter this so that instead of having the points shown for each iteration I could have a line plot where as the loop continuous, the line extends in time? Hope this makes sense.

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2012-12-9
g = 9.81;
u = 60;
t = 0:0.1:12.3; % time in seconds
for i = 1:length(t);
s(i)= (u.*t(i))-(g.*t(i).^2)./ 2;
plot(t(i),s(i));
xlim([0 14]);
ylim([0 200]);
hold on;
drawnow
title('Vertical motion under gravity');
xlabel('time');
ylabel('vertical displacement');
end
figure
plot(t,s)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by