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

3 次查看(过去 30 天)
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)');

回答(1 个)

David Hill
David Hill 2020-4-15
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.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by