Natural number determination
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rafael Freire
am 28 Jul. 2011
Beantwortet: Sang Eun Lee
am 16 Mai 2016
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 Kommentare
Akzeptierte Antwort
the cyclist
am 28 Jul. 2011
A == round(A)
That will give a 1 for integers. You can add a test for positiveness if you want it.
3 Kommentare
Matt Tearle
am 28 Jul. 2011
I prefer "evil genius"
(BTW, ismember(A,1:max(A)) actually works quite well, as long as max(A) is not too large...)
Weitere Antworten (2)
Sang Eun Lee
am 16 Mai 2016
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 Kommentare
Walter Roberson
am 28 Jul. 2011
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 Kommentare
Siehe auch
Kategorien
Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!