Finding integers in an array

8 vues (au cours des 30 derniers jours)
Edgar Diaz
Edgar Diaz le 26 Mai 2018
Commenté : Luke Ramel le 10 Mar 2023
I have an array with integers and non-integers. Is there a 'find' function where I can gather only the integers from the array?

Réponse acceptée

Stephan
Stephan le 26 Mai 2018
Modifié(e) : Stephan le 26 Mai 2018
Hi,
try this:
A = [5 0.1 -3 -4 -0.5 9 0 11 12 5 0.5]
A =
Columns 1 through 5
5.0000 0.1000 -3.0000 -4.0000 -0.5000
Columns 6 through 10
9.0000 0 11.0000 12.0000 5.0000
Column 11
0.5000
B = A(round(A(:)) == (A(:)))
B =
5 -3 -4 9 0 11 12 5
Best regards
Stephan
  3 commentaires
Rucheru Naicker
Rucheru Naicker le 10 Mar 2020
Thanks this helped sooo much.
Luke Ramel
Luke Ramel le 10 Mar 2023
Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by