Error:Index exceeds matrix dimensions.

1 visualización (últimos 30 días)
KalMandy
KalMandy el 13 de Nov. de 2016
Respondida: Jan el 14 de Nov. de 2016
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 comentario
Alexandra Harkai
Alexandra Harkai el 14 de Nov. de 2016
What is the actual code you're running?
What is crossX?

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 14 de Nov. de 2016
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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by