Index exceeds matrix dimensions.

Dear all, I have this array, "" ONU_queueNP{N} = [] ""
ONU_queueNP{i} = [ONU_queueNP{i}; ArrivingTime PacketSize];
and in a line after, I have these instructions:
Instant = ONU_queueNP{i}(1,1);
Size = ONU_queueNP{i}(1,1);
So, in Instant' I get the error "Index exceeds matrix dimensions" knowing that this was used before and it does not give an error. What can be the problem please?
Thank you in advance.

댓글 수: 5

Walter Roberson
Walter Roberson 2018년 6월 24일
ArrivingTime and PacketSize might both have been empty when you assigned to ONU_queueNP{i}, so ONUP_queueNP{1} might not have an index (1,1)
Note: you probably want Size to be accessed as (1,2)
Aziza Zaouga
Aziza Zaouga 2018년 6월 24일
Thank you for your answer.
But, in fact, i am using a counter that is incremented everytime ONUP_queueNP{i} is filled, so if (counter>0) the ONUP_queueNP{i} is not empty so for sure , it has an index(1,1). So it is the same to use Size. isn't it?
N = 5;
ONU_queueNP{N} = [];
This would create ONU_queueNP as a cell array of length 4, each containing a 0 x 0 double.
Now, let
global ArrivingTime PacketSize
i = 1;
ONU_queueNP{i} = [ONU_queueNP{i}; ArrivingTime PacketSize]
and observe:
ONU_queueNP =
1×5 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
You added an empty row to the end of an empty row, getting an empty row. And now ONU_queueNP{i} is empty so ONU_queueNP{i}(1,1) is index out of range.
Aziza Zaouga
Aziza Zaouga 2018년 6월 25일
Thanks again, But even when I putted [a,b] = size(ONU_queueNP{i})]; I got the same error 'Index exeeds matrix dimensions'. does it mean that there is no column i? thank you
Walter Roberson
Walter Roberson 2018년 6월 25일
You could first check size(ONU_queueNP) . If you get index exceeding matrix dimension on that, then check whether you accidentally created a variable named "size"

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

답변 (0개)

카테고리

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

질문:

2018년 6월 24일

댓글:

2018년 6월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by