How to check whether all the elements are integer?

19 views (last 30 days)
I had a vector of size (1 x 65536). How can i check whether all the elements in that vector is an integer.
  1 Comment
Sneha P S
Sneha P S on 5 Apr 2018
There some values are stored as 8.8744e+05 while checking the workspace. Is that a problem for doing bitxor operation. Those values are also considered as integers, right?

Sign in to comment.

Accepted Answer

Von Duesenberg
Von Duesenberg on 5 Apr 2018
check = [1 1.5];
logical(~rem(check,1))
  1 Comment
Peter H Charlton
Peter H Charlton on 6 Feb 2025 at 14:19
Edited: Peter H Charlton on 6 Feb 2025 at 14:20
This produces a logical array indicating whether each element is an integer. If you want to check whether all the elements in an array are integers, then I would suggest a slight edit:
check = [1 1.5];
sum(rem(check,1))==0 % check that there are no non-integers
ans = logical
0
check = [1 1];
sum(rem(check,1))==0 % check that there are no non-integers
ans = logical
1

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!