Plot not displaying lines
12 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!