adding a for loop for a super simple code

조회 수: 7 (최근 30일)
Gerrit Feyen
Gerrit Feyen 2021년 12월 7일
댓글: Voss 2021년 12월 8일
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