Error: Index exceeds matrix dimensions.

So I'm trying to access the column of a matrix called EEG.data that I created: EEG.data(chan,:) and I keep getting: Index exceeds matrix dimensions. However, I am able to access EEG.data(chan) which returns the following:
>>EEG.data(chan)
ans =
126.8809 25.0000
and >>size(EEG.data)
ans =
48 233268
Maybe I'm misunderstanding the use of :, but what exactly is my issue here?

 Accepted Answer

Just a guess here, but I bet you are doing the equivalent of this:
>> A = magic(7);
>> chan = [3 40];
>> A(chan)
ans =
46 44
>> A(chan,:)
Index exceeds matrix dimensions.
In the first case (which works), you are actually using a linear index to access the 3rd and then the 40th element (counting down successive columns).
In the second case (which gives an error), the syntax is such that you are trying to access the 3rd and 40th rows of A. Hence, the index exceeds the dimension.

2 Comments

Ahhh I see. I thought that A(chan,:) meant it indexed the same elements as A(chan) did plus the columns they were contained in. Thanks!
No problem. As you may have figured out, ":" actually means "all elements along this dimension".

Sign in to comment.

More Answers (0)

Asked:

on 25 Jul 2013

Community Treasure Hunt

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

Start Hunting!