Natural number determination
41 次查看(过去 30 天)
显示 更早的评论
In a vector how a determinate if the values is a natural number or not A=[ 1 2.2 3 5 6 8.8 9.6 ]
0 个评论
采纳的回答
the cyclist
2011-7-28
A == round(A)
That will give a 1 for integers. You can add a test for positiveness if you want it.
3 个评论
Matt Tearle
2011-7-28
I prefer "evil genius"
(BTW, ismember(A,1:max(A)) actually works quite well, as long as max(A) is not too large...)
更多回答(2 个)
Sang Eun Lee
2016-5-16
Hello I'm stuendt of Chung Nam National University in Korea. I'm very impressed of your command and I use it very usefully. Thanks A lot
0 个评论
Walter Roberson
2011-7-28
You can also check whether A>0 and mod(A,1) is non-zero .
The methods so far all suffer from loss of precision as the numbers increase, being only able to work with the nearest IEEE 754 double-precision representation to the number instead of the number itself.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!