If you really want to have the weights before and after the training of NN you can use these codes :
for n1=4:8
wb1=rand(n1,n_input);
wb2=rand(n_output,n1);
bb1=rand(n1,1);
bb2=rand(n_output,1);
wb=[wb1(:);wb2(:);bb1;bb2]';
xlswrite(['weight' num2str(n1) '.xlsx'],wb,'Sheet1',num2str(n1));
end
if n1==4
wb = xlsread(['weight' num2str(n1) '.xlsx']);
i1 = n1*n_input;
i2 = n_output*n1;
i3 = n1;
i4 = n_output;
f1=wb(1:i1);
f2=wb(i1+1:i1+i2);
f3=wb(i1+i2+1:i1+i2+i3);
f4=wb(i1+i2+i3+1:i1+i2+i3+i4);
wb1=reshape(f1,n1,n_input);
wb2=reshape(f2,n_output,n1);
bb1=reshape(f3,n1,1);
bb2=reshape(f4,n_output,1);
elseif n1==5
wb=xlsread(['weight' num2str(n1) '.xlsx']);
i1=n1*n_input;
i2=n_output*n1;
i3=n1;
i4=n_output;
f1=wb(1:i1);
f2=wb(i1+1:i1+i2);
f3=wb(i1+i2+1:i1+i2+i3);
f4=wb(i1+i2+i3+1:i1+i2+i3+i4);
wb1=reshape(f1,n1,n_input);
wb2=reshape(f2,n_output,n1);
bb1=reshape(f3,n1,1);
bb2=reshape(f4,n_output,1);
elseif n1==6
wb=xlsread(['weight' num2str(n1) '.xlsx']);
i1=n1*n_input;
i2=n_output*n1;
i3=n1;
i4=n_output;
f1=wb(1:i1);
f2=wb(i1+1:i1+i2);
f3=wb(i1+i2+1:i1+i2+i3);
f4=wb(i1+i2+i3+1:i1+i2+i3+i4);
wb1=reshape(f1,n1,n_input);
wb2=reshape(f2,n_output,n1);
bb1=reshape(f3,n1,1);
bb2=reshape(f4,n_output,1);
elseif n1==7
wb=xlsread(['weight' num2str(n1) '.xlsx']);
i1=n1*n_input;
i2=n_output*n1;
i3=n1;
i4=n_output;
f1=wb(1:i1);
f2=wb(i1+1:i1+i2);
f3=wb(i1+i2+1:i1+i2+i3);
f4=wb(i1+i2+i3+1:i1+i2+i3+i4);
wb1=reshape(f1,n1,n_input);
wb2=reshape(f2,n_output,n1);
bb1=reshape(f3,n1,1);
bb2=reshape(f4,n_output,1);
elseif n1==8
wb=xlsread(['weight' num2str(n1) '.xlsx']);
i1=n1*n_input;
i2=n_output*n1;
i3=n1;
i4=n_output;
f1=wb(1:i1);
f2=wb(i1+1:i1+i2);
f3=wb(i1+i2+1:i1+i2+i3);
f4=wb(i1+i2+i3+1:i1+i2+i3+i4);
wb1=reshape(f1,n1,n_input);
wb2=reshape(f2,n_output,n1);
bb1=reshape(f3,n1,1);
bb2=reshape(f4,n_output,1);
end
net = newff(inputs,targets,4,{'tansig','purelin'},'trainlm');
n.IW{1,1}=wb1;
n.LW{2,1}=wb2;
n.b{1}=bb1;
n.b{2}=bb2;
And after training for saving the network you want :
[net tr] = train(net,inputs,targets);
wb11=n.IW{1,1};
wb22=n.LW{2,1};
bb11=n.b{1};
bb22=n.b{2};
wbzz=[wb11(:);wb22(:);bb11;bb22]';
xlswrite('weight.xlsx',wbzz,'Sheet1');