How to use if statement to test if it is a integer and real number?
Mostrar comentarios más antiguos
x = input('enter the number: ');
if isreal(x)
else
delete x
if isinteger(x)
delete x
end
end
I try to do it, but it doesn't work.How to make it? It just a part of the whole script. It requires to delete the number if it isn't a integer or real number.
Respuesta aceptada
Más respuestas (1)
Andrew Newell
el 5 de Mayo de 2014
An integer is also a real number, so you only need one test. Also, if you want to delete numbers that are not real, you need to use a tilde (~) for negation. Assuming the input is always numeric, this will work:
x = input('enter the number: ');
if ~isreal(x)
clear('x');
end
2 comentarios
Andrew Newell
el 5 de Mayo de 2014
Judging by the multitude of errors in your short code snippet, I would strongly recommend working through at least one of the MATLAB Tutorials and Learning Resources.
Shi Yuhao
el 5 de Mayo de 2014
Categorías
Más información sobre Test Apps en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!