Number of inputs does not match net.numInputs. Custom-made net problem.
2 views (last 30 days)
Show older comments
Hello,
I am composing my own custom net for use in a school project.
I am currenly basing my code off an example in the MATLAB documentation and I was able to get that documentation code to work.
However I am now trying to read in my own data from an excel sheet and run the net using this data, and this is where I run into the error.
The data reads into correctly, however the error reads "Number of inputs does not match net.numInputs."
I put in some debugging code so see the size of my inputs and the result is below. 

The input is clearly an array of 3x21135.
In my code I have defined the input as 3 as shown below.
Any help would be apprciated.
net = network;
net.numInputs = 3;
net.numLayers = 3;
net.biasConnect(1) = 1;
net.biasConnect(3) = 1;
net.inputConnect(1,1) = 1;
net.inputConnect(2,1) = 1;
net.inputConnect(2,2) = 1;
net.inputConnect(3,1) = 1;
net.inputConnect(2,3) = 1;
net.inputConnect(3,3) = 1;
net.layerConnect = [0 0 0; 0 0 0; 1 1 1];
net.outputConnect = [0 1 1];
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.layers{1}.size = 4;
net.layers{1}.transferFcn = 'tansig';
net.layers{1}.initFcn = 'initnw';
net.layers{2}.size = 3;
net.layers{2}.transferFcn = 'logsig';
net.layers{2}.initFcn = 'initnw';
net.layers{3}.initFcn = 'initnw';
net.inputWeights{2,1}.delays = [0 1];
net.inputWeights{2,2}.delays = 1;
net.layerWeights{3,3}.delays = 1;
net.initFcn = 'initlay';
net.performFcn = 'mse';
net.trainFcn = 'trainlm';
net.divideFcn = 'dividerand';
net.plotFcns = {'plotperform','plottrainstate'};
0 Comments
Answers (1)
TED MOSBY
on 7 Jul 2025
Hi,
To remove the above error, you can do the following changes in the code:
net.numInputs = 1;
net.numInputs = 3; tells MATLAB that the network expects three independent input ports. You were feeding a single numeric matrix, so MATLAB saw only one incoming port. Changing the value to 1 aligns the definition (one port) with the data you actually pass.
You can delete all inputConnect references to columns 2 & 3 as those ports no longer exist.
Add the following line:
net.inputs{1}.size = 3;
It tells MATLAB how many features arrive on that port.
Hope this helps!
0 Comments
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!