Determine integers in an array and show the results

Hello, my friends
New to Matlab user
Let's say I want to determine the integers in x=[1 2.5 3.6 4] and get the result x_int=[1 4]. How can I do it?
Thank you

2 comentarios

Jan
Jan el 18 de Nov. de 2016
If the readers assume, that you ask a homework question, the answers are not complete, because you can create a solution by your own and submit it without cheating then.
rbarata
rbarata el 18 de Nov. de 2016
Then the readers should assume that for everybody, just in case. This is not an homework. I'm 50 years old and an engineer for more than 25, so I'm just a curious guy trying to do some exercises from a pdf that I've found in the web. :)

Iniciar sesión para comentar.

 Respuesta aceptada

rbarata
rbarata el 18 de Nov. de 2016
Editada: rbarata el 18 de Nov. de 2016
Thanks for the reply, Walter
Since all the other functions are for rounding operations, I think the best opt is to do something like this:
mod(x,1)
So, the condition to select my data (the integers) could be those elements on which mod(x,1)==0. But how do I select them in order to show them as the result? I could use b=find(mod(x,1)==0) but it gives me the indexes (position in the array) and not their values.

Más respuestas (2)

Walter Roberson
Walter Roberson el 18 de Nov. de 2016
Integral have several properties that can be tested:
  • round() and floor() and ceil() and fix() of the value equals the value itself
  • mod() of the value with 1 equals 0
rbarata
rbarata el 18 de Nov. de 2016
Thank you Walter. It worked.

1 comentario

Please use the "Comment on this Answer" buttons instead of adding a new Answer each time.

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 18 de Nov. de 2016

Comentada:

el 18 de Nov. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by