How do you plot a graph when using a while loop?

3 vues (au cours des 30 derniers jours)
Kristen A
Kristen A le 14 Avr 2020
When I run this code, I get a blank graph. How would I fix the code so that I would be able to see the actual graphed data?
V0=100;
G=9.8;
theta=pi/4;
T=-0.01;
while (T<=20)
T=T+0.01;
HT=T*V0*cos(theta);
end
plot(T,HT);
title('horizontal path');
xlabel('time(s)');
ylabel('distance(m)');

Réponses (1)

David Hill
David Hill le 15 Avr 2020
V0=100;
G=9.8;
theta=pi/4;
T(1)=-0.01;
c=0;
while (T<=20)
c=c+1;
T(c+1)=T(c)+0.01;
HT(c)=T(c+1)*V0*cos(theta);
end
plot(T(2:end),HT);
title('horizontal path');
xlabel('time(s)');
ylabel('distance(m)');
Much easier without a loop.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by