How to graph dashed reference line at 0?
Afficher commentaires plus anciens
I can't figure out how to graph a dashed line at 0 through the end of the graph (which would represent the ground). Currently the script I have is:
clear
clc
h=1.5; %m, height of ball at release
g=9.8; %m/s/s, gravity
%ask users for v and angle inputs
v=input('Enter velocity of ball at release:');
theta=input('Enter angle of ball at release:');
t=linspace(0,1,1000);%interval for 1 sec
x=v*cos(theta*(pi/180))*t; %formula for distance
y=h+(v*(sin(theta*(pi/180))))*t-(.5*g*t.^2); %formula for when height=0
x1=find(y<0);%assigns x1 the value of the vector list for when y<0
distance=x(x1(1)); %calculates x at when y=0
%Display answer to user
fprintf('The ball hits the ground at a distance of %d meters.\n', distance)
xlabel('Distance travelled (m)')
ylabel('Height travelled (m)')
title('Trajectory of Ball')
plot(x,y)
hold on
plot([0,0],[v,0], '--')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!