You don't give enough information to diagnose why this is happening in your code, but here is an example of that error and how it arises:
idx1 = [false true false true];
idx2 = [false true false true false];
idx3 = [false true false true false true];
x(idx3)
The logical indices contain a true value outside of the array bounds.
The last three lines of this code use logical indexing to access the element of the vector x. In general, logical indexing pulls out the values where the index it true. Typically, the index would have the same number of elements as the vector, as is the case with idx1.
idx2 also works, because the "extra" element of the index -- the 5th one -- is false, and therefore does not attempt to access the 5th element of x (which does not exist.)
But idx3 gives an error, because it tries to access the 6th element of x, which does not exist. In other words, "The logical indices contain a true value outside of the array bounds." (In this case, a true value beyond element 4.)
0 Comments
Sign in to comment.