%% Train Neural Network Using |trainlm| Train Function
% This example shows how to train a neural network using the |trainlm|
% train function.
%
% Here a neural network is trained to predict body fat percentages.

[x, t] = bodyfat_dataset;
for j=1:10
max_t=1;
net = feedforwardnet(30, 'trainlm');
net = train(net, x, t/max_t);
y = net(x);
y=y*max_t;
figure
plot(1:length(y),y,'ro');hold on
plot(1:length(y),t,'x');hold on
smse(j)=sqrt(mean((y-t).^2));
fprintf('sqrt of mse = %f\n ',sqrt(mean((y-t).^2)));
end