How can i make my code interactive?

8 次查看(过去 30 天)
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