MATLAB APP DESIGNER INPUT EDIT FIELD. PLEASE HELP!!

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

采纳的回答

Michael Van de Graaff
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by