checking that a user input is an integer
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jonathan Bird
el 19 de Feb. de 2018
Respondida: Star Strider
el 19 de Feb. de 2018
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});
0 comentarios
Respuesta aceptada
Star Strider
el 19 de Feb. de 2018
There are several ways of testing to see if the returned value is an integer.
You want to see if there is any non-zero value to the right of the decimal, so test for that. You can also experiment with the rem or mod functions.
0 comentarios
Más respuestas (1)
Roger Stafford
el 19 de Feb. de 2018
Test whether this is true. If so, 'prompt' is an integer, otherwise it is not.
prompt==round(prompt)
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!