フィルターのクリア

How to Limit input to a whole interger?

8 ビュー (過去 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 Center および File ExchangeNaNs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by