How can i make my code interactive?

조회 수: 8 (최근 30일)
Amanda Michel
Amanda Michel 2019년 4월 15일
답변: Rik 2019년 4월 15일
I want to let people choose Forces and Angles then it will give them the answer of a total force.
For my first section i am already given 3 angles and 3 forces where i find the total force and result angle.
I started to use 'Force1= input('Enter force');
for all forces and angles then put end at the end of that but when i run it it just keeps going on. Then i put the equations underneath that for the total force and result angle but it doesnt run.
  댓글 수: 2
Rik
Rik 2019년 4월 15일
Show the code you're using. The input function is indeed the function you should be using (unless you want to make a GUI).
Amanda Michel
Amanda Michel 2019년 4월 15일
%% 1st section
Force = [100, 200, 50];
theta = [-90, 90, 30];
% angle to radians
theta = theta.*pi/180;
%sum and components of X
ForceX = Force.*cos(theta);
XFORCEtotal = sum(ForceX);
%sum and components of Y
YFORCEtotal = sum(Force.*sin(theta));
%result angle (radians)
resultangle = atan(YFORCEtotal./XFORCEtotal);
%convert to degrees
resultangleDEGREE = resultangle.*180/pi
TOTALFORCE = XFORCEtotal./cos(resultangle)
%mesh
[XForce, Ytheta] = meshgrid (Force, theta);
Z = peaks(XForce, Ytheta);
surf (XForce, Ytheta, Z)
%% 2nd section interactive
valid = 0
while valid == 0
Force1 = input('Enter 1st Force');
Force2 = input('Enter 2nd Force');
Force3 = input('Enter 3rd Force');
Angle1 = input('Enter 1st angle');
Angle2 = input('Enter 2nd angle');
Angle3 = input('Enter 3rd angle');
hold on;
ForceALL = [Force1, Force2, Force3];
AngleALL = [Angle1, Angle2, Angle3];
AngleALL = AngleALL.*pi/180;
XForceALL_total = sum(ForceALL.*sin(theta));
YForceALL_total = sum(ForceALL.*cos(theta));
Angle_Result = atan(YForceALL_total./XForceALL_total);
Angle_ResultDegrees = Angle_Result.*180/pi
Total_Force = XForceALL_total./cos(Angle_Result)
hold off;
end
disp('Angle_ResultDegrees');
disp('Total_Force');

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2019년 4월 15일
You aren't checking if the values are valid. That means you're never changing the value of valid, which results in an endless loop.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by