Index exceeds matrix dimensions.

I get error message 'Index exceeds matrix dimensions' wiht the following code. I will appreciate help.
for i = 1:length( Vmean ),
GroupMean = GroupMean + Vmean{i}.Y(1,strt:fnsh);
GroupStd = GroupStd + Vstd{i}.Y(1,strt:fnsh);

Réponses (2)

Matt J
Matt J le 25 Déc 2014
Modifié(e) : Matt J le 25 Déc 2014

0 votes

"fnsh" is greater than the length of either Vmean{i}.Y or Vstd{i}.Y
Hence, there is nothing there for Vmean{i}.Y(fnsh) or or Vstd{i}.Y(fnsh) to grab.
Use
>>dbstop if error
to find the offending i.

3 commentaires

Rajendra
Rajendra le 25 Déc 2014
Thanks.. can you suggets a fix?
Matt J
Matt J le 25 Déc 2014
I suggested that you use DBSTOP, which should have led you to the fix.
Rajendra
Rajendra le 25 Déc 2014
Modifié(e) : Rajendra le 25 Déc 2014
Thanks Matt. I changed the script to: GroupMean = GroupMean ./ length( Vmean ); GroupStd = GroupStd ./ length(Vmean ); It resolved the issue at this point but get another error message downstream the following script:
oldTimes = [ (min(V.start_times ) - .5 ) ... (V.start_times + .5 * duration) ... (max(V.start_times + duration ) + .5 ) ];
Error: Error using + Matrix dimensions must agree.
Error in interpT_VOL (line 26) oldTimes = [ (min(V.start_times ) - .5 ) ...
I think matrix dimensions are OK. I will very much appreciate any suggestion.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 25 Déc 2014

0 votes

I suggest you make fnsh not more than the number of columns in Y. What does this say
theYarray = Vmean{1}.Y;
whos theYarray
The whos command will tell you how many rows and columns are in Y. See if the number of columns is less than fnsh. If it is, then you need to figure out why you're trying to specify fnsh with the value that you did.

6 commentaires

Rajendra
Rajendra le 25 Déc 2014
Thanks.. for some reason it resturns error message: Undefined variable "V.mean". I however chnaged the script and as mentioned above, got another message. I am copying my comment above: I changed the script to: GroupMean = GroupMean ./ length( Vmean ); GroupStd = GroupStd ./ length(Vmean ); It resolved the issue at this point but get another error message downstream the following script:
oldTimes = [ (min(V.start_times ) - .5 ) ... (V.start_times + .5 * duration) ... (max(V.start_times + duration ) + .5 ) ];
Error: Error using + Matrix dimensions must agree.
Error in interpT_VOL (line 26) oldTimes = [ (min(V.start_times ) - .5 ) ...
I think matrix dimensions are OK. I will very much appreciate any suggestion.
oldTimes = [(min(V.start_times ) - .5 ) ...
(V.start_times + .5 * duration) ...
(max(V.start_times + duration ) + .5 ) ];
Rajendra
Rajendra le 25 Déc 2014
This is the code which is returning the matrix error
Image Analyst
Image Analyst le 25 Déc 2014
You called it Vmean, not V.mean. Anyway, did you try my second/last suggestion (the link)?
Rajendra
Rajendra le 27 Déc 2014
I did try the tips on the link.. very helpful but still not easy to locate the probelm when you are dealing with multiple scripts.. if you think there is no syntazx error in the code, I will keep looking for pther leads.. it is frustrating. I very much appreciate your help though..
Image Analyst
Image Analyst le 27 Déc 2014
We can't really do much more unless you upload the program and the data so we can then use the debugger to step through your code (same as what I asked you to do). Using the debugger and finding out what the dimensions and indexes are is the way to solve this problem. If you can't do it then we/someone might do it for you but we require code and data.

Connectez-vous pour commenter.

Tags

Question posée :

le 24 Déc 2014

Commenté :

le 27 Déc 2014

Community Treasure Hunt

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

Start Hunting!

Translated by