Effacer les filtres
Effacer les filtres

Error:Index exceeds matrix dimensions.

1 vue (au cours des 30 derniers jours)
KalMandy
KalMandy le 13 Nov 2016
Réponse apportée : Jan le 14 Nov 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 commentaire
Alexandra Harkai
Alexandra Harkai le 14 Nov 2016
What is the actual code you're running?
What is crossX?

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 14 Nov 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by