【问题标题】:Subscript indices must be real positive integers, and they are (Matlab) [duplicate]下标索引必须是实数正整数,它们是(Matlab)[重复]
【发布时间】:2014-06-12 20:13:41
【问题描述】:

我正在尝试在 Matlab 中编写一个简单的反向传播网络,但出现以下错误:

Subscript indices must either be real positive integers
or logicals.

在我的代码的第 144 行,在本节中:

for l = 1:net.layerCount,
         if l == 1, % From input layer
             for i = round(1:net.inputSize),
                 i % i = 1 and
                 l % l = 1 when I get the error.
                 % error in this next line:
                 net.weight{l}(i,:) = net.weight{l}(i,:) ...
                       - sum(lrate .* net.delta{l} .* net.layerOutput{l-1}(i)) ...
                       - (momentum .* net.previousWeightDelta{l}(i,:));
                 net.previousWeightDelta{l}(i,:) = net.weight{l}(i,:);
             end
         else
            for i = 1:net.layerSize{l-1},
                net.weight{l}(i,:) = net.weight{l}(i,:) ...
                       - sum(lrate .* net.delta{l} .* net.layerOutput{l-1}(i)) ...
                       - (momentum .* net.previousWeightDelta{l}(i,:));
                net.previousWeightDelta{l}(i,:) = net.weight{l}(i,:);
            end
         end
     end

即使我用 round() 包围 1:net.layerCount 和其他循环向量,错误仍然存​​在。知道为什么会这样吗?

谢谢!

【问题讨论】:

  • 哪一行返回这个错误? “144”在这里并不能说明太多……
  • dbstop if error 和 which 该行中的所有内容以检查您是否没有任何杂散阴影变量 - 如果您的 i/l价值观就是你所说的。看看骗子。

标签: matlab runtime-error backpropagation


【解决方案1】:

在l == 1的情况下,你非法尝试使用

net.layerOutput{l-1}

0 不是正数。

输入层需要使用输入,而不是层间连接。

【讨论】:

  • 天哪,谢谢。这就是你不复制粘贴代码的原因。
  • @DavidMyers:以后用“分而治之”吧。无论哪一行或表达式出错,将其一小部分放入交互式命令窗口,直到找到问题所在。
猜你喜欢
  • 2012-11-27
  • 2013-12-04
  • 1970-01-01
  • 2014-02-02
  • 2012-12-29
  • 2014-09-25
  • 2013-04-19
  • 2012-04-14
相关资源
最近更新 更多