The logical indices in position 1 contain a true value outside of the array bounds.
Mostra commenti meno recenti
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)
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 Commenti
the cyclist
il 2 Gen 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.
Claire R
il 2 Gen 2021
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.
Walter Roberson
il 2 Gen 2021
0 voti
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
Walter Roberson
il 2 Gen 2021
Another possibility is that when you used CV partition that you told it a size larger than your input
Claire R
il 2 Gen 2021
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.
2 Commenti
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.
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!