Why isnt my graph showing a line?

2 Ansichten (letzte 30 Tage)
Charles Combs
Charles Combs am 11 Feb. 2021
Beantwortet: Walter Roberson am 11 Feb. 2021
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')

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Feb. 2021
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.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by