checking that a user input is an integer
显示 更早的评论
The user is told to input an integer between 1 and 59 but I want an error message to display if the value they enter is not an integer. This is what I have so far:
prompt = {'Enter your first integer between 1 and 59'};
dlg_title = 'User inputs';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines);
u=str2double(answer{1});
采纳的回答
更多回答(1 个)
Roger Stafford
2018-2-19
Test whether this is true. If so, 'prompt' is an integer, otherwise it is not.
prompt==round(prompt)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!