I am new to using matlab I am trying make a network which has 20 inputs and one output, when i run the code it says :

"Error using ==> network/sim
Inputs are incorrectly sized for network.
Matrix must have 39 rows. "
and points to the line NNA=sim(NN,I)

Below is how I have declared I. Can anybody point me in the right direction with this error? If more code is needed please ask.

I=A(:,1:20)';
T=A(:,21:21)';
NNA=sim(NN,I)

Anybody? I have looked over it a few times and just don't know where it is getting 39 from

Below is how I have declared I. Can anybody point me in the right direction with this error? If more code is needed please ask.

I=A(:,1:20)';
T=A(:,21:21)';
NNA=sim(NN,I)

I am no expert in MATLAB, but I would find it helpful to see more of your code, specifically, the declaration of A.

NN=network;
NN.numInputs=20;

NN.inputs{1}.size=20;
NN.numLayers=2;
NN.layers{1}.size=12;
NN.layers{2}.size=5;

NN.inputConnect(1)=1;
NN.layerConnect(2,1)=1;
NN.outputConnect(2)=1;
NN.targetConnect(2)=1;
NN.biasConnect(1)=1;
NN.biasConnect(2)=1;

NN.layers{1}.transferFcn='logsig'; 
NN.layers{2}.transferFcn='logsig';

NN.initFcn='initlay';

NN.layers{1}.initFcn='initwb';
NN.inputWeights{1,1}.initFcn='rands';
NN.biases{1}.initFcn='rands';

NN.layers{2}.initFcn='initwb';
NN.layerWeights{2,1}.initFcn='rands';
NN.biases{2}.initFcn='rands';

NN=init(NN);

load testData.txt;
A=testData;
I=A(:,1:20)';
T=A(:,20:20)';

NNA=sim(NN,I)


NN.trainFcn='trainb';

NN.inputWeights{1,1}.learnFcn='learngd';
NN.biases{1}.learnFcn='learngd';
NN.layerWeights{2,1}.learnFcn='learngd';
NN.biases{2}.learnFcn='learngd';

NN.performFcn='mse';
NN.trainParam.lr=1;
NN.trainParam.goal=0.001;
NN.trainParam.epochs=50000;
%NN.trainParam.show=100;

[NN,tr]=train(NN, I, T);

NNA=sim(NN,I)

Thats the enitre code

well this reply is probably too late for the user but the line that says NN.laysers{2}.size=5 near the beginning is telling the program that there are five neurons in layer 2. I would expect this to be 1 becayse later in you said 20 inputs and one output. Id look around that point first...

NN=network;
NN.numInputs=20;

NN.inputs{1}.size=20;
NN.numLayers=2;
NN.layers{1}.size=12;
NN.layers{2}.size=5;

NN.inputConnect(1)=1;
NN.layerConnect(2,1)=1;
NN.outputConnect(2)=1;
NN.targetConnect(2)=1;
NN.biasConnect(1)=1;
NN.biasConnect(2)=1;

NN.layers{1}.transferFcn='logsig'; 
NN.layers{2}.transferFcn='logsig';

NN.initFcn='initlay';

NN.layers{1}.initFcn='initwb';
NN.inputWeights{1,1}.initFcn='rands';
NN.biases{1}.initFcn='rands';

NN.layers{2}.initFcn='initwb';
NN.layerWeights{2,1}.initFcn='rands';
NN.biases{2}.initFcn='rands';

NN=init(NN);

load testData.txt;
A=testData;
I=A(:,1:20)';
T=A(:,20:20)';

NNA=sim(NN,I)


NN.trainFcn='trainb';

NN.inputWeights{1,1}.learnFcn='learngd';
NN.biases{1}.learnFcn='learngd';
NN.layerWeights{2,1}.learnFcn='learngd';
NN.biases{2}.learnFcn='learngd';

NN.performFcn='mse';
NN.trainParam.lr=1;
NN.trainParam.goal=0.001;
NN.trainParam.epochs=50000;
%NN.trainParam.show=100;

[NN,tr]=train(NN, I, T);

NNA=sim(NN,I)

Thats the enitre code

This article has been dead for over six months. Start a new discussion instead.