MATLAB: Does the neural network fail to train when I introduce feedback components using Neural Network Toolbox 6.0 (R2008a)

Deep Learning Toolbox

I am creating a custom Elman network as follows and attempting to train it:
clear variables;
p = rand(2,10);
t = rand(2,10);
net=newelm(p,t,[5,4,2],{'tansig','tansig','purelin'},'trainrp');
net.layerConnect(1,1)=0;
net.layerConnect(2,2)=0;
net.layerConnect(1,3)=1;
net=init(net);
[net,tr]=train(net,p,t);
However I get the following error message
??? Error using ==> network.train at 129
Network contains a zero-delay loop.

Best Answer

This error occurs because the following line in the code
net.layerConnect(1,3)=1;
creates a feedback loop with a zero delay connection between the output of the third hidden layer and the input of the first layer, which implies that there is no good starting point for training the network.
In general, all non-feed-forward lines require non-zero delays. To make the above network work, one can modify the delay value as follows
net.layerWeights{1,3}.delays = [1];