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?

 채택된 답변

the cyclist
the cyclist 2013년 7월 25일

1 개 추천

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

Dude
Dude 2013년 7월 25일
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!
the cyclist
the cyclist 2013년 7월 25일
No problem. As you may have figured out, ":" actually means "all elements along this dimension".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2013년 7월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by