This behavior is expected. There are two general reasons why returning an integer is preferable in this situation: First, integer data types are often used in situations where limiting memory usage is important, so it is useful that MATLAB returns a result that similarly conserves memory. Secondly, doubles are the default data type in MATLAB, so in a simple command such as:
the number 1 is a double, but the user would reasonably expect the output to be an int8. Making the output of an operation between doubles and integers always be an integer ensures this.
It is important to note that, while doubles and integers can be combined using an operator such as addition, subtraction, etc., integers of different classes (such as int8 and int16) cannot be combined using an operator.
Best Answer