How to Limit input to a whole interger?

조회 수: 23 (최근 30일)
Michael  Kurniawan
Michael Kurniawan 2012년 10월 5일
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?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 5일
편집: Azzi Abdelmalek 2012년 10월 5일
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
Walter Roberson
Walter Roberson 2012년 10월 5일
while mod(a,1)
can be used to replace
while fix(a)-a~=0

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by