필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do I fix: Index exceeds array bounds.

조회 수: 1 (최근 30일)
jakobjakob
jakobjakob 2018년 6월 10일
마감: Star Strider 2018년 6월 11일
j= 1:length(index_aanname);
for j= 1:length(index_aanname)
for l=1:length(alldata)
if ((strcmp(alldata(l,3), SA{j})) && ((TA(1,j) - alldata{l,1}) <= 10.0) && ((TA(1,j) - alldata{l,1}) >= 0) && (strcmp(alldata(l,4), 'Voor'))) == 1
eerste_kijkmoment(l) = tijdnum(l);
j=j+1;
end
end
end
j goes up to 240. I know that in the loop it goes to 241, that's why there is an error. But how do I fix this? I know it ask more often over here, but I cannot come to an answer...
  댓글 수: 2
Majid Farzaneh
Majid Farzaneh 2018년 6월 10일
Hi,
Why you are using j=j+1?
What is the size of SA and TA?
Error occurs because of j=j+1. It cause increasing of j exceed SA or TA size.
jakobjakob
jakobjakob 2018년 6월 10일
I added SA.mat and TA.mat. I know the error is there because of j=j+1, but how can I fix it?

답변 (1개)

Star Strider
Star Strider 2018년 6월 10일
If you want to increment ‘j’ inside the ‘l’ loop, the easiuest way is to reverse the order of the for calls:
for l = 1:length(alldata)
for j = 1:length(index_aanname)
... CODE ...
end
end
  댓글 수: 2
jakobjakob
jakobjakob 2018년 6월 10일
The error is gone, but it did not fix my problem. I have a file about footbal looking behaviour. I want the first 'viewing behaviour' (=eerste_kijkmoment) in the 10 seconds before every first ball touch (=aanname). Your code with my code gave all the viewing behaviour and not only the first viewing behaviour before the first ball touch. Can you help me?
Star Strider
Star Strider 2018년 6월 10일
I have no idea how to interpret your ‘SA’ and ‘TA’ data, or even what they mean or what you want to do with them.
I cannot help you further.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by