Error:Index exceeds matrix dimensions.
1 view (last 30 days)
Show older comments
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 Comment
Answers (1)
Jan
on 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.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!