MATLAB Answers

The logical indices in position 1 contain a true value outside of the array bounds.

234 views (last 30 days)
Claire R
Claire R on 2 Jan 2021
Commented: the cyclist on 2 Jan 2021
What does this error mean?
The logical indices in position 1 contain a true value outside of the array bounds.
Error in file (line 28)
class =
classify(Input(test,:),Input(train,:),Output(train,:));
thank you for your help

  0 Comments

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 2 Jan 2021
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:
x = [2 3 5 7];
idx1 = [false true false true];
idx2 = [false true false true false];
idx3 = [false true false true false true];
x(idx1)
ans = 1×2
3 7
x(idx2)
ans = 1×2
3 7
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.)

  4 Comments

Show 1 older comment
the cyclist
the cyclist on 2 Jan 2021
Are you able to also upload your data in a MAT file, so that we can run your code? (You can use the paper clip icon in the INSERT section of the toolbar to attach files.)
It seems to me that my answer (which I think is arising via the possibility Walter suggested in his comment on his own answer) is probably correct. But we can't test that idea without the data.
the cyclist
the cyclist on 2 Jan 2021
Is what you put in as "Output" in your code the variable "BCTable"? I cannot emphasize enough how important it is to put up a complete set of data/code that people can run and duplicate the error you are seeing, without all this guesswork.
Unfortunately, I don't have access to the Bioinformatics Toolbox, so I cannot run the classperf command.
Have you used the debugger at all? I would recommend stopping your code at the line that give the error, to see if you variables are the size you expect.

Sign in to comment.


Walter Roberson
Walter Roberson on 2 Jan 2021
It means that Output in your code is a row vector but you are accessing it as if it were either a column vector or a 2d array.

  2 Comments

Walter Roberson
Walter Roberson on 2 Jan 2021
Another possibility is that when you used CV partition that you told it a size larger than your input
Claire R
Claire R on 2 Jan 2021
hi, thank you for answering,i have posted the whole code, if it can help you better understand my error

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by