【问题标题】:Can't understand the warning无法理解警告
【发布时间】:2013-09-09 08:19:05
【问题描述】:

我的代码可以运行,但每次运行到第 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

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

【问题讨论】:

  • 听起来像pos 包含非整数......也许position 给出了标准化坐标,它们是非整数。您可以在第 13 行之前将其打印到屏幕上吗?这说明了什么?

标签: matlab compiler-warnings


【解决方案1】:

这可能是因为以下一项或多项:pos(2)pos(2)+pos(4)pos(1)pos(1)+pos(3) 不是整数,而索引应该是整数。您可能需要使用round 函数将它们向上舍入为整数值。

【讨论】:

    【解决方案2】:

    玛雅人,

    问题似乎来自您的 pos 向量的值(以及您对 pos 向量值进行的计算的值)。

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

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

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 2011-09-27
      相关资源
      最近更新 更多