How to use if statement to test if it is a integer and real number?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Andrew Newell
le 5 Mai 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 commentaires
Andrew Newell
le 5 Mai 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
le 5 Mai 2014
Catégories
En savoir plus sur Big Data Processing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!