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 Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by