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)');
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!