Question
I am new to using the machine learning toolboxes of MATLAB (but loving it so far!) From a large data set I want to fit a neural network, to approximate the underlying unknown function. I have used the "Neural Net Fitting" app and generated a script with it which builds and trains my network. It all works, however the results are not good enough. I think the network is not complex enough to cover the non-linearities. So, I figued I'd add another hidden layer, but I can't get it to work. The current code to produce the network is the following (which is the default): trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. % Create a Fitting Network hiddenLayerSize = 10; net = fitnet(hiddenLayerSize, trainFcn); How would I modify this to add more hidden layers? I am looking to get the classical Multi-Layer Perceptron (MLP) network, with potentially even more hidden layers:
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 29, 2026
You can add more hidden layers as shown below:
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation. % Create a Fitting Network hiddenLayer1Size = 10; hiddenLayer2Size = 10; net = fitnet([hiddenLayer1Size hiddenLayer2Size], trainFcn);
This creates network of 2 hidden layers of size 10 each.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related deep learning Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →