Error-Checking for Integers:
As MATLAB uses the type double by default for all the values, to check to make confirm that the user has entered an integer, the program have to convert the input value to an integer type (e.g., int32) and then check to see whether it is equivalent to the original input. The following illustrations illustrate the concept.
When the value of the variable num is a real number, converting it to the type int32 will round it; therefore the result is not similar as the original value.
>> num = 3.3;
>> inum = int32(num)
>> num == inum
If, on another hand, the value of the variable num is an integer, convert it to an integer type will not change the value.
>> num = 4;
The script below uses this idea to error-check for integer data; it loops until the user properly enters an integer.