How can I show the error message when the input data get wrong?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to create the inputdlg to let user to input the data. But how can I add the check coding to check the input is between 2000 and 2019? Thank you.
My current coding:
prompt = {'Start Year:','End Year:'};
dlgtitle = 'Year Range (Between 2000 and 2019)';
dims = [1 50];
answer = inputdlg(prompt,dlgtitle,dims);
disp(answer)
0 Commenti
Risposta accettata
VBBV
il 11 Dic 2022
Modificato: VBBV
il 11 Dic 2022
prompt = {'Start Year:','End Year:'};
dlgtitle = 'Year Range (Between 2000 and 2019)';
dims = [1 50];
answer = inputdlg(prompt,dlgtitle,dims);
if str2num(answer{1}) < 2000 | str2num(answer{2}) > 2019 % check the condition for year range
disp('Error: please enter valid range')
else
disp(answer)
end
Più risposte (1)
KSSV
il 11 Dic 2022
prompt = {'Start Year:','End Year:'};
dlgtitle = 'Year Range (Between 2000 and 2019)';
dims = [1 50];
answer = inputdlg(prompt,dlgtitle,dims);
while any(str2double(answer)<2019) || any(str2double(answer) > 2020)
answer = inputdlg(prompt,dlgtitle,dims);
end
disp(answer)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!