- What is the problem you are trying to solve?
- What are the inputs and which components (edit fields, sliders, etc.) are you using in the app?
- What release are you working on?
Change value of variable in while loop
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
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?
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!