How to Limit input to a whole interger?

23 vues (au cours des 30 derniers jours)
Michael  Kurniawan
Michael Kurniawan le 5 Oct 2012
Hi Im trying to tell matlab to only allow input for whole numbers only i.e no numbers such as 23.4. How do I do this? also by doing this do I also stop any inputs that are imaginary?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 5 Oct 2012
Modifié(e) : Azzi Abdelmalek le 5 Oct 2012
test=0
while test==0
a=input('enter integer number')
if fix(a)-a==0
test=1
else
disp('Only integer numbers are allowed')
end
end
  1 commentaire
Walter Roberson
Walter Roberson le 5 Oct 2012
while mod(a,1)
can be used to replace
while fix(a)-a~=0

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by