"Index exceeds the number of array elements"
古いコメントを表示
I've been getting an index exceed the number of array elemnts (2048)
How to I solve this?
回答 (2 件)
Cris LaPierre
2020 年 7 月 30 日
0 投票
Use an index that is not greater than the dimension you are indexing. For example, if your array is a 1x2048, you will get this error is you try to index row 2 or column 2049.
4 件のコメント
Jarren Berdal
2020 年 7 月 30 日
Cris LaPierre
2020 年 7 月 30 日
How are you indexing? That is what is causing the problem. What is the value of your index when you get the error?
Jarren Berdal
2020 年 7 月 30 日
編集済み: Walter Roberson
2020 年 7 月 30 日
Cris LaPierre
2020 年 7 月 30 日
What is the value of
- R
- N (5?)
What is the size of DATE
Walter Roberson
2020 年 7 月 30 日
We do not know what R is.
If we suppose R is the 409 and N is 5, then on the last iteration, when i = 409, then p = 409*5 = 2045, and p+1:p+N = 2046 : 2050, but the array is only 2048 long.
Meanwhile, when i = 1, then p=i*N = 5, and p+1:p+N is 5+1 : 5+5 = 6:10 . Notice that you have not accessed index 1:5 .
The solution:
23 - p = (i*N);
should be
23 - p = ((i-1)*N);
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!