plotting in time domain - update plot

1 visualizzazione (ultimi 30 giorni)
Richard
Richard il 9 Dic 2012
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.

Risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 9 Dic 2012
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)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by