MATLAB APP DESIGNER INPUT EDIT FIELD. PLEASE HELP!!

6 Ansichten (letzte 30 Tage)
hgrlk
hgrlk am 22 Mai 2021
Kommentiert: hgrlk am 28 Mai 2021
HELLO,
I have a problem with matlab app designer. I'm trying to do something, when I give input into "age", if it is not between the range, a warning message appears. But I want to do this as a loop. I mean, if I give wrong input, app shows me an warning message, and then I must rewrite new value. But my code doesnt control again my value. I cannot find the code about give new input to Edit Field number.
If you can help me I will be very glad. Thank you!
% Value changed function: ageoffirstpilotEditField
function ageoffirstpilotEditFieldValueChanged(app, event)
value_age = app.ageoffirstpilotEditField.Value;
flag1 = false;
while flag1 == false;
if app.ageoffirstpilotEditField.Value < 25 || app.ageoffirstpilotEditField.Value > 60
f = warndlg('The range of pilot age should be between [25,60]. Try again!','Invalid Input');
app.KparameteroffirstpilotEditField.Value = 0;
%%%%
else
break
end
end
end

Akzeptierte Antwort

Michael Van de Graaff
Michael Van de Graaff am 22 Mai 2021
Does something like this do what you want?
function ageoffirstpilotEditFieldValueChanged(app, event)
goodage = 0;
while goodage==0
value = app.ageoffirstpilotEditField.Value;
if value< 25 || value>60
goodage = 0;
prompt = 'enter age 25<= age<= 60';
title = 'Age out of range';
dims = 1;
defaultage = {'40'};
answer = inputdlg(prompt, title,dims,defaultage);
app.ageoffirstpilotEditField.Value = str2num(answer{1});
elseif value> 25 && value<60
goodage = 1;
end
end
disp('success')
end

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by