MATLAB: Do I get a warning about ‘Integer Operands Are Required for Colon Operator When Used as Index’

MATLAB

Why do I get the following error message:
Warning: Integer operands are required for colon operator when used as index.

Best Answer

Explanation:
You have used a noninteger value as one of the parameters (starting value, increment, or stopping value) for the colon (:) operator when using it to create a vector of indices to reference into a function.
Common causes:
You performed computations to obtain the starting or stopping values for the indexing but the result of those computations was not exactly an integer.
Solution:
Modify the index computations using the FIX, FLOOR, CEIL, or ROUND functions to ensure that the indices are integers. You can test if a variable contains an integer by comparing the variable to the output of the ROUND function operating on that variable when MATLAB is in debug mode on the line containing the variable.
Example demonstrating this error:
IntegerOperandsRequired.m