adding a for loop for a super simple code

9 次查看(过去 30 天)
I am trying to add a for loop to determine if the result of my dist equation are greater than or less than 100 yards, then displaying whether it made across or not. I am however illiterate when it comes to coding. I got up to this and need some basic help on how to integrate a for loop here for this application, or if I should use something else
disp('A ball is launched on a football field, does it clear the whole field?');
Vi = input('How fast is the ball released in mph? ');
A = input('At what angle do you release this ball in degrees? ');
V_mps = (Vi/0.44704);
A_rad = A*(pi/180);
t_hit = 2*(V_mps/9.8)*sin(A_rad);
t_max = t_hit/2;
dist = V_mps*t_hit*cos(A_rad);

回答(1 个)

Voss
Voss 2021-12-7
If I understand correctly, it seems like you can say:
if dist >= 100 % 100 meters, assuming your unit conversions are ok. convert 100 yards to the same units of dist to compare dist to 100 yards instead.
display('made it');
else
display('did not make it');
end
  2 个评论
Gerrit Feyen
Gerrit Feyen 2021-12-7
Thank you! I thought I might need another condition beforehand. Even though it's my own fault I am coding illiterate in an engineering program I will choose to blame the stupid software. Thank you again for the tip!
Voss
Voss 2021-12-8
No problem. Please mark my answer as accepted, if you don't mind. I appreciate it.
And BTW, everybody's got to start somewhere! Solving programming problems in an engineering program is probably an ideal way to get good at coding. And if you get stuck, someone here will be able to help out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by