无法理解警告

时间:2013-09-09 08:19:06

标签: matlab compiler-warnings

我的代码可以运行,但每次运行第13行时都会在命令窗口中写入:“警告:冒号操作符需要整数操作数 当用作索引时“。 我的代码的相关部分看起来像这样:

  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

为什么会出现此警告,我可以忽略它吗?

2 个答案:

答案 0 :(得分:3)

可能是因为以下一项或多项:pos(2)pos(2)+pos(4)pos(1)pos(1)+pos(3)不是整数,应该是哪些索引。您可能希望使用round函数将它们四舍五入为整数值。

答案 1 :(得分:1)

Maayan,

问题似乎发生在你的pos矢量值(以及你对pos矢量值的计算值)。

这是MathWorks(MATLAB)网站引用的解决方案: http://www.mathworks.com/support/solutions/en/data/1-FA9A2S/?solution=1-FA9A2S

  

使用FIX,FLOOR,CEIL或ROUND函数修改索引计算,以确保索引是整数。当MATLAB在包含变量的行上处于调试模式时,您可以通过比较变量和在该变量上运行的ROUND函数的输出来测试变量是否包含整数。

相关问题