Plot not displaying lines
Ältere Kommentare anzeigen
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
Antworten (1)
Adam Danz
am 12 Dez. 2021
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 Kommentare
Gerrit Feyen
am 12 Dez. 2021
Adam Danz
am 12 Dez. 2021
How does the height vary through time? Which variable represents time and which variable represent height at each time point?
Gerrit Feyen
am 12 Dez. 2021
Gerrit Feyen
am 12 Dez. 2021
Kategorien
Mehr zu Physics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!