필터 지우기
필터 지우기

Error:Index exceeds matrix dimensions.

조회 수: 1 (최근 30일)
KalMandy
KalMandy 2016년 11월 13일
답변: Jan 2016년 11월 14일
I have two arrays;
onpointX1 =
NaN NaN NaN NaN NaN NaN NaN
onpointX2 =
NaN NaN NaN NaN NaN 0.5830 0.5161
Note that the elements which are not NaN always equal to crossX(k,1) or crossX(k,2).
I run a for loop,
for k=1:length(onpointX1)
onpointX1(8)=onpointX1(1);
onpointX2(8)=onpointX2(1);
I get an error when the for loop is at k=7
Index exceeds matrix dimensions.
at;
else if isnan(onpointX1(k)) && onpointX2(k)==crossX(k,2)&& onpointX1(k+1)==crossX(k+1,1) && isnan(onpointX2(k+1))
I can not understand why this happens because I have defined onpointX1(8) and onpointX2(8) right after initiationg the for loop.
Can anybody help me with this? Thanks.
  댓글 수: 1
Alexandra Harkai
Alexandra Harkai 2016년 11월 14일
What is the actual code you're running?
What is crossX?

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

답변 (1개)

Jan
Jan 2016년 11월 14일
Use the debugger for further investigations:
dbstop if error
Run the code again until it stops at the error and check the dimensions of the used variables:
size(onpointX1)
size(onpointX2)
size(crossX)
Then you will find out, which variable causes the error.
Debugging locally is more efficient than asking the forum, which cannot guess the details.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by