Change value of variable in while loop

조회 수: 4 (최근 30일)
Anon 2020년 12월 23일
답변: Mischa Kim 2020년 12월 24일
Hi all, I have included a while loop to check that theta0 is between (or equal to) 0 and 90
(GetHori and GetVert are my anonymous functions for the hori and vert components)
however im not sure how i can allow for the user to input their new values before the while loop restarts?
is there anyway to prompt the user to change the values in the edit field? without using the 'pause' function?
if this wasnt in app designer i would have used v1 = input('Please input new value: ') but this doesnt work in the app designer
the code i have currently is:
%-----------Calculation of resolved initial velocity: ---------------------
v0 = sqrt(v0x^2+v0y^2)
theta0 = tand(v0y/v0x)
%%---------Checking whether the angle is in the 1st quadrant: -------------
if theta0 < 0 || theta0 > 90
while theta0 > 90 || theta0 < 0
app.MESSAGETextArea.Value = ['Sorry! Those velocity directions have produced a projectile' ...
'going in an unexpected direction- please input different directions!']
v1 = app.Velocity1EditField.Value;
v2 = app.Velocity2EditField.Value;
v3 = app.Velocity3EditField.Value;
mag1 = app.Direction1EditField.Value;
mag2 = app.Direction2EditField.Value;
mag3 = app.Direction3EditField.Value;
%-----------Calculation of the x,y components for each: -------------------
v1y = GetVert(v1,mag1)
v1x = GetHori(v1,mag1)
v2y = GetVert(v2,mag2)
v2x = GetHori(v2,mag2)
v3y = GetVert(v3,mag3)
v3x = GetHori(v3,mag3)
%-----------Calculation of the resolved x,y components: -------------------
v0y = v1y+v2y+v3y
v0x = v1x+v2x+v3x
%-----------Calculation of resolved initial velocity: ---------------------
v0 = sqrt(v0x^2+v0y^2)
theta0 = tand(v0y/v0x)
thank you v much in advance!!
  댓글 수: 4
Mischa Kim
Mischa Kim 2020년 12월 23일
Thanks for the info. Why are there 3 different velocities and 3 different directions? Are these initial velocities (at launch)? Is this to simulate one projectile in 3D (x-, y-, z-direction), or, are there multiple projectiles? I do not quite understand why you have the 3 terms and then compute v0x and v0y. Can you help clarify?
Anon 2020년 12월 24일
I was just instructed to ask for multiple velocity’s and their direction to which I resolved them into one velocity in one direction there’s no particular reason other than difficulty

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

답변 (1개)

Mischa Kim
Mischa Kim 2020년 12월 24일
Hi Anon,
based on your problem description and assuming you are simulating the motion of one projectile in 3D I suggest you use the 3 velocities to define vx0, vy0, and vz0, the components of the initial velocity vector of the projectile. You can remove the 3 edit fields for the directions; they are not needed as the velocity vector is defined by its 3 components. For the velocity components use Edit Field (Numeric) as this allows you to set limits for the range of values. For example, if you want to make sure that the projectile is launched upwards you could set the limits for vx0 to be between 0 and +Inf. This would--sort of--be the check that you are asking for above in your initial post. Hope this helps.


Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by