- comparisons were done on floating point numbers expecting equality between a computed value and a constant, or expecting equality between two computed values. Due to round-off problems, if you compute two floating point numbers in even trivially different ways the two numbers might come out unequal; floating point numbers should be compared to within a tolerance.
- an "if" was done on a condition that was being thought of as a scalar (a single value) but a vector or array was involved. When "if" is applied to a vector or array, the condition is only considered to be true if all values in the vector or array are non-zero ("true"). When this is not realized then it is common to end up with the variable undefined or with a variable assigned a scalar when it should be a vector.
Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
why does this error become "Attempted to access sidelobes(2); index out of bounds because numel(sidelobes)=1."
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i am working with the algorithm and problem. there is a huge lines of code i cant upload it. i just want to know why this error occurs in matlab so i will sort out some solutions for my code? error is
Attempted to access sidelobes(2); index out of bounds because numel(sidelobes)=1.
0 commentaires
Réponses (1)
Walter Roberson
le 5 Oct 2015
The error occurs because you tried to access the second element of sidelobes when sidelobes only has one element. There are a lot of different reasons why it might only have one element, including that that is all that was ever put into there. There are a couple of more common reasons the problem might show up:
2 commentaires
Walter Roberson
le 6 Oct 2015
Notice that all the tests are conditional for incrementing count and assigning to sidelobes(count) . It is not obvious that any of the conditions are necessarily true.
You appear to be searching for local peaks. There are other ways of doing that, such as finding the places that diff(yax) transitions between non-negative and negative: non-negative stretches are staying the same or increasing and when you hit negative then you are starting to decline. You could have an indefinite run of staying the same before declining, so you need to decide which one of those identical values is "the" peak.
If your yax values do not have at least two declines in different stretches, then you would not have at least two peaks. You should be examining your yax values to figure out why.
sign(diff(yax))
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!