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 ]

 Respuesta aceptada

the cyclist
the cyclist el 28 de Jul. de 2011

4 votos

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

3 comentarios

Matt Tearle
Matt Tearle el 28 de Jul. de 2011
ismember(A,1:realmax) mwahahahaha!
Oleg Komarov
Oleg Komarov el 28 de Jul. de 2011
@Matt you're a troll!!! :)
Matt Tearle
Matt Tearle el 28 de Jul. de 2011
I prefer "evil genius"
(BTW, ismember(A,1:max(A)) actually works quite well, as long as max(A) is not too large...)

Iniciar sesión para comentar.

Más respuestas (2)

Sang Eun Lee
Sang Eun Lee el 16 de Mayo de 2016

1 voto

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 el 28 de Jul. de 2011

0 votos

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.

Categorías

Más información sobre Discrete Data Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 28 de Jul. de 2011

Respondida:

el 16 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by