The logical indices in position 1 contain a true value outside of the array bounds.
31 views (last 30 days)
Show older comments
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
Answers (3)
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)
x(idx2)
x(idx3)
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
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.
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.
4 Comments
the cyclist
on 16 Jun 2023
Just as we advised Claire two years ago, please post your code and your data so we can replicate exactly what you are seeing, and get the error.
I think it would be better for you to post a new question with that info, rather than making a comment on a two-year-old question. More people will see it.
Ajmal
on 16 Jun 2023
Edited: Ajmal
on 16 Jun 2023
2 Comments
the cyclist
on 16 Jun 2023
The problem is with the size of featureMatrix.
You create that "matrix" with this code:
featureMatrix = [cell2mat(entropyFeatures), cell2mat(energyFeatures)];
which creates a 1x1000 vector (not a 2-dimensional matrix).
Then, in this line of code
trainFeatures = featureMatrix(cvp.training, :);
you are accessing featureMatrix as if it were a 2-dimensional matrix.
I can't be certain what you intended, but if you take the transpose of entropyFeatures and energyFeature before using cell2mat
featureMatrix = [cell2mat(entropyFeatures.'), cell2mat(energyFeatures.')];
then featureMatrix will be 100x10, and the rest of the code will run.
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!