Plot not displaying lines

12 次查看(过去 30 天)
Gerrit Feyen
Gerrit Feyen 2021-12-12
评论: Gerrit Feyen 2021-12-12
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

回答(1 个)

Adam Danz
Adam Danz 2021-12-12
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 个评论
Gerrit Feyen
Gerrit Feyen 2021-12-12
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 2021-12-12
*the balls remain in the air for about 5 seconds I believe

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by