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')

采纳的回答

Walter Roberson
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 个)

类别

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