Index exceeds matrix dimensions?

1 view (last 30 days)
Muzafar Pandit
Muzafar Pandit on 13 Oct 2012
clear
format compact
load testinria3;
xn=x';
yn=y;
noin=face;
clear x y noin
%load testinriapos3
invar=[yn(1:60,:);xn(1:50,:)];
outclass=[ones(60,1),zeros(60,1);
zeros(50,1),ones(50,1)];
%%neural network
net=newpr(invar',outclass',50);
net.trianParam.epochs=5000;
net.trainParam.goal=0.001;
net.trainParam.max_fail=5000;
net=train(net,invar,'outclass');
I extracted negative features(of testinria3)=1218 and positive features (of testinriapos3)=1126 but it's now showing the error as
Index exceeds matrix dimensions.
Error in newneural (line 14)
invar=[yn(1:60,:);xn(1:50,:)];
Kindly help me in rectifying this error. I have two files as- pos(with size 1218*1344) and neg(with size 1126*1126)
  2 Comments
Walter Roberson
Walter Roberson on 13 Oct 2012
At the command line, command
dbstop if error
and run the program. When it stops, examine size(xn) and size(yn)
Muzafar Pandit
Muzafar Pandit on 4 Feb 2013
while doing the same as you suggested, it shows size(xn) = 1218 1344 size(yn)= 1 1218

Sign in to comment.

Answers (3)

Greg Heath
Greg Heath on 15 Oct 2012
> clear
>format compact
>load testinria3;
>xn=x';
>yn=y;
>noin=face;
What are x, y, and face ??
What are their dimensions ?
>clear x y noin
Why are you clearing noin instead of face ?
%load testinriapos3
>invar=[yn(1:60,:);xn(1:50,:)];
Implying that xn and yn have the same number of columns,I, the dimensionality of the input space. Then,
size(invar) = [ N I ] = [110 I ]
>outclass=[ones(60,1),zeros(60,1); > zeros(50,1),ones(50,1)];
size(outclass) = [N c ] = [110 2 ] % c = 2 classes (x and y)
This provides Neq = N*c = 220 output equations
%neural network
> net=newpr(invar',outclass',50);
With H = 50 hidden nodes, there are
Nw = (I+1)*H+(H+1)*c = 50*I + 50 + 102 = 152 +50 * I unknown weights.
If I > 2, there are more unknowns than equations, and you may have problems. I recommend reducing H so that Nw <= Neq and ,if possible, Nw << Neq.
Other possibilities are to use validation set stopping or regularized training with trainbr.
>net.trianParam.epochs=5000;
Unnecessary. Why not just accept the internal default of 1000?
>net.trainParam.goal=0.001;
A good value depends on the scale of outclass. If Nw < ~ 0.5* Neq,
MSEgoal = 0.01*(Neq-Nw)*mean(var(outclass))/Neq
is a reasonable choice
>net.trainParam.max_fail=5000;
The default is 6. Since your value virtually eliminates validation stopping, you should either drastically reduce H or use trainbr.
>net=train(net,invar,'outclass');
SYNTAX ERROR. Move the 1st parentheses
>I extracted negative features(of testinria3)=1218 and positive features (of testinriapos3)=1126 but it's now showing the error as
Ambiguous terminology. Typically, I, the dimesionality of the input column vectors, is considered the number of input features.
Please explain these numbers.
>Index exceeds matrix dimensions. >Error in newneural (line 14) >invar=[yn(1:60,:);xn(1:50,:)];
This implies you have 60 I-dimensional yn measurements and 50 I-dimensional xn measurements.
The net is only valid for I-dimensional input column vectors.
>Kindly help me in rectifying this error. I have two files as- pos(with size 1218*1344) and neg(with size 1126*1126)
Neither of these sizes makes sense. If one file is class x and the other is class y,the dimensionality of the input vectors in each array should be I.
Now if I >= 1126, you have a very serious problem. You don't need hundreds of dimensions to separate two classes.
Please explain all of the dimensions of all your matrices.
Hope this helps.
Thank you for formally accepting my answer.

Walter Roberson
Walter Roberson on 4 Feb 2013
Your code line
invar=[yn(1:60,:);xn(1:50,:)];
is attempting to access yn as if it were a column vector or 2D array with at least 60 rows. But it isn't -- it is a row vector.
Perhaps when you set
yn=y;
you wanted
yn=y .';
??
  2 Comments
Muzafar Pandit
Muzafar Pandit on 4 Feb 2013
I did same but it's showing following error: Error using vertcat CAT arguments dimensions are not consistent. Error in newneural (line 14) invar=[yn(1:60,:); xn(1:50,:)];
Walter Roberson
Walter Roberson on 4 Feb 2013
What are you expecting as the outcome? You are selecting 60 elements from one array, and 50 x 1344 from the other array, so what size of matrix is your expected result?

Sign in to comment.


Greg Heath
Greg Heath on 5 Feb 2013
Edited: Greg Heath on 5 Feb 2013
This can be cleared up very quickly by answering the following questions
What physical quantities do the vectors in xn and yn represent?
What are the dimensionality of the vectors in xn? 1218?
How many vectors are in xn? 1344?
How many are you using in your example? 50? Why?
What are the dimensionality of the vectors in yn? 1218?
How many vectors are in yn? 1126?
How many are you using in your example? 60? Why?
Are these questions easier to answer than the ones I asked in Oct?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!