Why isnt my graph showing a line?
조회 수: 2 (최근 30일)
이전 댓글 표시
For some reason my graph isnt shoing a line. Can some one help?
%% Initial conditions
x0= 2; %m/s
y0= 2.5; %m/s
v0= 5; %m/s
theta=45; %degrees
ax= 0;
ay= -9.8; %m/s
%% Equations
V0y=v0*sin(theta);
theta_rad = theta * pi/180;
v0x = v0*cos(theta_rad);
v0y = v0*sin(theta_rad);
t_end1=(-(V0y)-sqrt((V0y)*20)^2-4*(.5*ay)*y0)/(2*((.5)*ay));
t_end2=(-(V0y)+sqrt((V0y)*20)^2-4*(.5*ay)*y0)/(2*((.5)*ay));
x= x0+v0x*t_end1+1/2*ax*t_end1.^2;
y= y0+v0y*t_end1+1/2*ay*t_end1.^2;
%% If statment
if(t_end1>=0)
tend=t_end1;
else
tend=tend2;
end
display(tend)
%% Graphing
subplot(2,2,1)
plot(y,x)
title('x vs y')
subplot(2,2,2)
plot(y,tend1)
title('t vs y')
subplot(2,2,3)
plot(x,tend1)
title('t vs x')
댓글 수: 0
채택된 답변
Walter Roberson
2021년 2월 11일
in MATLAB when you use plot() with numeric values, plot only produces a line is there are at least two consecutive points for which adjacent coordinates are finite.
At any given index, matlab checks isfinite for the current location and the next location, and only draws a line segment if both are.
In your case your x and y are scalar so there is no next point for matlab to draw to.
By default matlab does not put in markers. If you added a marker specification to the plot() you would see the single point being marked.
So what is wrong with your code? This: you only calculated and plotted the end point. You do not calculate and plot any of the points between. Notice that you do not have a vector of time values.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!