0
votes

My code works but every time it runs through line 13 it writes on the command window :"Warning: Integer operands are required for colon operator when used as index ". The relevant part of my code looks like that:

  filename = uigetfile;
    obj = mmreader(filename);
     nFrames=obj.NumberOfFrames;
     for k = 1 : nFrames  
    this_frame = read(obj, k);
    thisfig = figure();
    thisax = axes('Parent', thisfig);
    image(this_frame, 'Parent', thisax);

    if k==1
        handle=imrect;
        pos=handle.getPosition;
    end
    partOf=this_frame(pos(2):pos(2)+pos(4),pos(1):pos(1)+pos(3));%this is line 13
    vector(k)=mean2(partOf);
    title(thisax, sprintf('Frame #%d', k));

 end

Why this warning appears and can i ignore it?

2
Sounds to me like pos contains non-integers...Perhaps the position gives normalized coordinates, which are non-integers. Can you print it to the screen prior to line 13? What does that say?Rody Oldenhuis

2 Answers

3
votes

It's probably because one or more of the following: pos(2), pos(2)+pos(4), pos(1) and pos(1)+pos(3) are not integers, which indices are supposed to be. You may want to use the round function to round them up to integer values.

1
votes

Maayan,

The problem seems to occur from the values of your pos vector (and the value of the calculations you make to pos vector values).

This is the solution quoted from MathWorks(MATLAB) website: http://www.mathworks.com/support/solutions/en/data/1-FA9A2S/?solution=1-FA9A2S

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.