【问题标题】:Matlab) size func (Subscript indices must either be real positive integers or logicals)Matlab)大小函数(下标索引必须是实数正整数或逻辑数)
【发布时间】:2016-01-26 08:41:55
【问题描述】:

我想做函数,输出输入图像部分窗口的平均值。

所以,我在matlab中实现了简单的功能

`

[m] = function compute_mean ( Input, r,w, size )
% r,w is coordinate of window's central point.
a = size(Input);
b=size(a);
if(b(2) ==3 )
    Input = rgb2gray(Input);
end
row = a(1); col = a(2);
......

` 它没有警告。

但这会导致错误。在第 2 行中。( a = size(Input) ) 下标索引必须是实数正整数或逻辑数。

我不知道为什么会出现这个错误。

请给我一个解决方案,这种情况。

【问题讨论】:

    标签: matlab size subscript


    【解决方案1】:

    您的第 4 个输入参数,即 size,与 Matlab 的 size 函数同名。将大小更改为例如 sz。那么你的代码会变成这样:

    [m] = function compute_mean ( Input, r,w, sz)
    % r,w is coordinate of window's central point.
    a = size(Input);
    b=size(a);
    if(b(2) ==3 )
        Input = rgb2gray(Input);
    end
    row = a(1); col = a(2);
    ......
    

    在为函数或变量或参数选择名称之前,请务必检查它是否为 MATLAB 内部函数名称。否则,MATLAB 将考虑您定义的最后一个符号。

    【讨论】:

      猜你喜欢
      • 2012-11-27
      • 2013-12-04
      • 2012-12-29
      • 2014-09-25
      • 2013-04-19
      • 2012-04-14
      • 1970-01-01
      相关资源
      最近更新 更多