Hi John,
The error message Index exceeds the number of array elements (12) indicates that the size of the second input, [bestIW{i-1},bestLW{i-1}], does not align with the structure expected by the net in the MATLAB setwb function. Specifically, the setwb function requires a single vector that contains the combined weights and biases of the network, but the second input currently includes only the weights.
To solve the issue, you can follow the steps given below.
- Create the Weight Vector: Combine bestIW{i-1}, bestLW{i-1} and bias net.b into one vector:
weights = [bestIW{i-1}(:); bestLW{i-1}(:); net.b(:)]
- Set the Network Weights: Pass the combined vector to setwb():
net = setwb(net, weights);
After using MATLAB ‘setwb’ function, you do not need to run init(net) again, because the MATLAB setwb function directly sets the weights and biases.
For more information, please refer to following MATLAB documentation for ‘setwb’ function.
Hope it resolves your query.