plotting in time domain - update plot
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
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)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!