MATLAB: Testing Neural Network on new data

neural networknewffsim

I am quite new to MATLAB and extrmely new to neural networks. I have created a feed forward neural network using newff(). I input a matrix of size 486*1200 and output matrix 6*1200. When I simulate the network using sim() function after training, I get correct output. But when I try to simulate on any other input of shorter size I get error which says input matrix should have 486 rows (as that of training matrix).
Can anyone resolve this issue for me to generalize the network for any size of input? And if I make that matrix of 486 rows by padding extra zeros, it gives incorrect output even though that test matrix is a part of trainig matrix.
Here is my code:
[Pr,Pc] = size(PP);% Pr=486, Pc=1200
TP=eye(6,1200);
[Tr,Tc] = size(TP);
L1 = 0.5*Pc;
net0to9 = newff(minmax(PP),[L1 Tr],{'logsig' 'logsig'},'traingdx');
net0to9.performFcn = 'mse';
net0to9.trainParam.goal = 0;
net0to9.trainParam.show = 20;
net0to9.trainParam.epochs =1200;
[net0to9,Tr] = train(net0to9,PP,TP);
x = sim(net0to9,PP);
I'd be really thankful if anyone could help.

Best Answer

For newff() the samples run down the columns!
Note the documentation says:
P R x Q1 matrix of Q1 sample R-element input vectors
So the P(:,1) is the first sample, P(:,2) is the second sample, and so on.
Therefore, any data you test against must have Pr rows or else the samples will be incomplete.
If you intend that your samples are incomplete, then in order for a meaningful computation to take place, you would somehow have to indicate the mapping between the inputs you have available and the original input positions. I do not know if there is any mechanism for that at all, but if I were designing such a mechanism, the way I would probably expect the user to indicate missing inputs would be by putting NaN in that input location.
I do not know much about NN, but I have seen several people run in to this same problem of not noticing that the samples run down the columns.