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 Comments

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.
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. :)

Sign in to comment.

 Accepted Answer

rbarata
rbarata on 18 Nov 2016
Edited: rbarata on 18 Nov 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.

More Answers (2)

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
Thank you Walter. It worked.

1 Comment

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

Sign in to comment.

Products

Tags

Asked:

on 18 Nov 2016

Commented:

on 18 Nov 2016

Community Treasure Hunt

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

Start Hunting!