필터 지우기
필터 지우기

How to graph dashed reference line at 0?

조회 수: 5 (최근 30일)
Jake Marvin
Jake Marvin 2016년 9월 14일
답변: Walter Roberson 2016년 9월 14일
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], '--')

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 14일
xL = get(gca, 'XLim');
plot(xL, [0 0], '--')
Remember, the ground is a height and height is Y rather than X.
The bit about getting the XLim is finding the left and right margins of what you currently have plotted; then the plot command plots a line across from the left to right margin.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by