error-index exceeds matrix dimension
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Walter Roberson
2012년 4월 17일
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.
추가 답변 (2개)
Andreas Goser
2012년 4월 17일
net=newff(P1(:,trains),Tar(:,trains),2);
throws an error in the first run, as Tar has no second dimension. Probably you mean:
net=newff(P1(:,trains),Tar(trains),2);
댓글 수: 3
Andreas Goser
2012년 4월 17일
You just asked why you got this error. Now you know ;-)
I may know more about MATLAB, but hope fully you know more about neural networks... The message "Inputs and targets have different numbers of samples." That sounds like an actionable error message, isn't it?
Greg Heath
2012년 4월 22일
1. The input and target matrices must have the same number of columns:
Tar = [ 0 0 1 1 ]
[ I N ] = size( P1) % [ 2 4 ] [ O N ] = size(Tar) % [ 1 4 ]
k = 10
indices=crossvalind('kfold',Tar,k)
2. a. It doesn't make sense to use k > N
b.Instead of using CROSSVALIND from the Bioinformatics TBX, the algorithm
might be more portable if you use CROSSVAL from the Statistics TBX.
3. trains= ~test
Rename. TRAINS is a MATLAB function.
Hope this helps.
Greg
댓글 수: 2
Greg Heath
2012년 4월 22일
Typical nontrivial classification examples should have classes with
many more I/O training pairs than input dimensions.
For the FisherIris example/demo (c = 3, I = 4, N = 150).
Although that ratio is
N/(3*4) = 12.5,
the scatter plot in the PetalLength/PetalWidth plane indicates
that the 3 classes are linearly separable with two hidden nodes.
Hope this helps.
Greg
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!