MATLAB: Error-index exceeds matrix dimension

matrix

In the following code i get error a s
P1 = [-1 -1 2 2; 0 5 0 5];
Tar = [0 ;1 ]
indices=crossvalind('kfold',Tar,10);
for i=1:10
test=(indices==i);trains= ~test
tst = (indices==i);
val = (indices== mod(i+1,10));
trn = ~[tst,val];
net=newff(P1(:,trains),Tar(:,trains),2);
net=init(net);
[net,tr]=train(net,P1(:,trains),Tar(:,trains));
out = round(sim(net,P(:,test)));
end
Index exceeds matrix dimensions.
Error in cfour (line 58)
net=newff(P1(:,trains),Tar(:,trains),2);
please help

Best Answer

That code is going to generate an error unless "indices" is of length 1 exactly. If it is longer than 1, then "test" and "train" will be longer than 1, and would then be too long to use as logical vectors against the columns of the single-column Tar array.