Change value of variable in while loop

2 views (last 30 days)
Anon
Anon on 23 Dec 2020
Answered: Mischa Kim on 24 Dec 2020
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)
end
end
thank you v much in advance!!
  4 Comments
Anon
Anon on 24 Dec 2020
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

Sign in to comment.

Answers (1)

Mischa Kim
Mischa Kim on 24 Dec 2020
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.

Community Treasure Hunt

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

Start Hunting!