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 Exchange에서 External Language Interfaces에 대해 자세히 알아보기

질문:

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