Search code examples
matlabruntime-errorbackpropagation

Subscript indices must be real positive integers, and they are (Matlab)


I am trying to code a simple backpropagation network in Matlab, and I am getting the following error:

Subscript indices must either be real positive integers
or logicals.

in line 144 of my code, which is during this section:

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

The error persists even if I surround 1:net.layerCount and the other loop vectors with round(). Any idea why this is the case?

Thanks!


Solution

  • In the l == 1 case, you illegally try to use

    net.layerOutput{l-1}
    

    0 is not positive.

    The input layer needs to use the inputs, not inter-layer connections.