How do you plot a graph when using a while loop?
3 views (last 30 days)
Show older comments
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)');
0 Comments
Answers (1)
David Hill
on 15 Apr 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.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!