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 ]

 採用された回答

the cyclist
the cyclist 2011 年 7 月 28 日

4 投票

A == round(A)
That will give a 1 for integers. You can add a test for positiveness if you want it.

3 件のコメント

Matt Tearle
Matt Tearle 2011 年 7 月 28 日
ismember(A,1:realmax) mwahahahaha!
Oleg Komarov
Oleg Komarov 2011 年 7 月 28 日
@Matt you're a troll!!! :)
Matt Tearle
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
Sang Eun Lee 2016 年 5 月 16 日

1 投票

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
Walter Roberson
Walter Roberson 2011 年 7 月 28 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeDiscrete Data Plots についてさらに検索

質問済み:

2011 年 7 月 28 日

回答済み:

2016 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by