plotting in time domain - update plot

1 visualización (últimos 30 días)
Richard
Richard el 9 de Dic. de 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.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 9 de Dic. de 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)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by