MATLAB: Warning: Integer operands are required for colon operator when used as index

r2010bwarning

For this code:
40: y1_x=y_data(1)
41: y1=round(y1_x)
42: y2_x=y_data(2)
43: y2=y2_x-y1_x+y1
I get this output(and warning):
y1_x =
57.3517
y1 =
57
y2_x =
83.3517
y2 =
83
Warning: Integer operands are required for colon operator when used as
index
> In sonar_prob at 43
In robot_diferential at 60
In Painel>RunSimulation at 259
In Painel>pushbuttonReactive_Callback at 154
In gui_mainfcn at 96
In Painel at 16
In @(hObject,eventdata)Painel('pushbuttonReactive_Callback',hObject,eventdata,guidata(hObject))
I couldn't find any reason for this warning…what can it mean?

Best Answer

This is caused by something like:
T = rand(1,10);
T(2.2:7.99) % Note the indexing by: 2.2:7.99
So you need to look through your code and spot where you are using a colon operator like the above. BTW, this fixes the warning message and produces the same output.
T(floor(2.2:7.99))
%
%
%
%
%
EDIT In response to your comments below:
Do this at the command line:
dbstop if warning
Then run the code again. The debugger will stop on the line that causes the warning...