Test for integer value
古いコメントを表示
I am trying to make a battleship styled game, one of the parts involve getting a set of user input 'firing coordinates', which I then need to test to make sure it is an integer value 1 through 10, what function can I use to test that it is an integer?
*edit: I am looking for a logical operator or else condition that can specify a non integer input.
採用された回答
その他の回答 (2 件)
Bruno Luong
2018 年 9 月 29 日
編集済み: Bruno Luong
2018 年 9 月 29 日
Perhaps no better no worse than James's solution just different
iswholenumber = mod(x,1)==0
Bruno Luong
2018 年 9 月 29 日
編集済み: Bruno Luong
2018 年 9 月 29 日
according to my test slightly faster, but need to assume the smaller range of x of be working:
x == int32(x)
カテゴリ
ヘルプ センター および File Exchange で Antennas, Microphones, and Sonar Transducers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!