MATLAB: How to Loop the neural network training to choose the best performance

annfitnetloopneural networkneuronstrainingtrials

Hi, I need some help on how to train a network for different value of Neurons, and save the MSE then choose the best MSE to select the best trained network.
I am using the fitnet as follows:
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network & set number of neurons
hiddenLayerSize = 30;
net = fitnet(hiddenLayerSize,trainFcn);
[net,tr] = train(net,X,T);
testX = X(:,tr.testInd);
testT = T(:,tr.testInd);
testY = net(testX);
perf = mse(net,testT,testY)