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

389 visualizzazioni (ultimi 30 giorni)
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

Risposte (3)

the cyclist
the cyclist il 2 Gen 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 Commenti
the cyclist
the cyclist il 2 Gen 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.

Accedi per commentare.


Walter Roberson
Walter Roberson il 2 Gen 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 Commenti
the cyclist
the cyclist il 16 Giu 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.

Accedi per commentare.


Ajmal
Ajmal il 16 Giu 2023
Modificato: Ajmal il 16 Giu 2023
Here you are sir the code is attached and datasets are linked
Thanks in advance
  2 Commenti
the cyclist
the cyclist il 16 Giu 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.
Ajmal
Ajmal il 16 Giu 2023
Modificato: Ajmal il 16 Giu 2023
Thank you so much sir that helped a lot really appreciate your work.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by