How do I test for integers in MATLAB?
integer, matlab
Solution
You can use the `mod` function, which returns the remainder after division. All integers are divisible by `1`. So a good test for non-integer would be
integerTest=~mod(value,1);
This returns `0` if `value` is not an integer and `1` if it is. You can then use this as a conditional to reject non-integer user inputs.
Problem
I'm writing a program that will calculate factorials of integers. However, the part I'm stuck on is if someone enters a non-integer such as `1.3`, I'd like to be able to test the input and display `"The number you have entered is not an integer"`