Plot not displaying lines

I have a simple project here and my plot comes up fine but without any line or points present. Just blank with a scaled X and Y axis. Thoughts?
%Test your might! Who's ball will clear a football field?
disp('Two people see who can throw farther, will they clear the field? Who will win?');
Vi = input('How fast is the first ball released in mph? ');
A = input('At what angle do you release this ball in degrees? ');
Vi1 = input('How fast is the second ball released in mph? ');
A1 = input('At what angle do you release this ball in degrees? ');
%Now we need conversion equations and kinematic equations to find the final
%distances
V_mps = (Vi*0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
dist= ((V_mps*t_hit*cos(A_rad))*1.09361);
t_max = t_hit/2;
x = ((V_mps.*t_max.*cos(A_rad))*1.09361);
y = ((V_mps.*t_max.*sin(A_rad)- 0.5*9.8*t_max^2)*1.09361);
%second throw
V_mps1 = (Vi1*0.44704);
A_rad1 = A1*(pi/180);
t_hit1 = 2*(V_mps1/9.8)*sin(A_rad1);
dist1 = ((V_mps1*t_hit1*cos(A_rad1))*1.09361);
t_max1 = t_hit1/2;
x1 = ((V_mps1.*t_max1.*cos(A_rad1))*1.09361);
y1 = ((V_mps1.*t_max1.*sin(A_rad1)- 0.5*9.8*t_max1^2)*1.09361);
plot (x, y, "r-");
plot (x1, y1, "r--");
%Final if statement to determine if the launch was over or under 100 yards
%and who won
if dist>= 100
fprintf('Player 1, you made it!');
else
fprintf('Player 1, you did not make it :(');
end
if dist1>= 100
fprintf('Player 2, you made it!');
else
fprintf('Player 2, you did not make it :(');
end
if dist> dist1
fprintf('Player 1 wins!');
end
if dist< dist1
fprintf('Player 2 wins!');
end
if dist == dist1
fprintf('It was a tie!')
end

Respuestas (1)

Adam Danz
Adam Danz el 12 de Dic. de 2021

0 votos

A line requires at least two points. Your x, x1, y, y1 values are scalars (single points). If you want to plot a marker instead of a line,
plot (x, y, "ro"); % circular marker
plot (x1, y1, "rs"); % square marker
Perhaps you meant to plot,
plot ([x, x1], [y, y1], "r-");

4 comentarios

Gerrit Feyen
Gerrit Feyen el 12 de Dic. de 2021
okay, this does give me a plot now, just connecting the two max heights. What I'm going for is plotting the height against time intervals on the x axis to get a parabolic graph of the motion. Should I just replace the t_max in my height (y, y1) equations with an increasing time so I get a value at each second?
Adam Danz
Adam Danz el 12 de Dic. de 2021
How does the height vary through time? Which variable represents time and which variable represent height at each time point?
Gerrit Feyen
Gerrit Feyen el 12 de Dic. de 2021
y and y1 were supposed to be the two thrown ball heights, I was copying another set of fuctions for plotting motion with the x and x1 since mine was not working. I want the height of the thrown ball from start to finish plotted as it goes through the air with the y and y1 equations. This is what I just tried and I got errors in my h(t) equations, just what I called y now.
V_mps = (Vi*0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
dist= ((V_mps*t_hit*cos(A_rad))*1.09361);
t_max = t_hit/2;
for t =0:10
h(t) = ((V_mps.*t.*sin(A_rad)- 0.5*9.8*t^2)*1.09361);
t = t+1;
end
%second throw
V_mps1 = (Vi1*0.44704);
A_rad1 = A1*(pi/180);
t_hit1 = 2*(V_mps1/9.8)*sin(A_rad1);
dist1 = ((V_mps1*t_hit1*cos(A_rad1))*1.09361);
t_max1 = t_hit1/2;
for t1 =0:10
h1(t) = ((V_mps1.*t1.*sin(A_rad1)- 0.5*9.8*t1^2)*1.09361);
t1 = t1+1;
end
y1 = ((V_mps1.*t_max1.*sin(A_rad1)- 0.5*9.8*t_max1^2)*1.09361);
plot ([t,t1],[y,y1], "r-");
Among other issues I think I need to define my variables better for the loops, idk I'm not great at this
Gerrit Feyen
Gerrit Feyen el 12 de Dic. de 2021
*the balls remain in the air for about 5 seconds I believe

Iniciar sesión para comentar.

Categorías

Más información sobre Physics en Centro de ayuda y File Exchange.

Preguntada:

el 12 de Dic. de 2021

Comentada:

el 12 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by