Subscript indices must either be real positive integers or logicals.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
how can i solve "Subscript indices must either be real positive integers or logicals." in this line?
selected_point = selected_ones(round(number/2))
0 commentaires
Réponses (1)
Kelly Kearney
le 22 Juin 2016
number is probably <0.5, and is therefore rounded to 0 (or a negative number). And as the error message says, indices have to real positive integers; 0 is not a valid index.
2 commentaires
Stephen23
le 23 Juin 2016
Modifié(e) : Stephen23
le 23 Juin 2016
@Nina B: if you want to fix your code your have to understand what your code is doing. You know what cause the error (a non-integer value (possibly zero) used as an index), and you know what line it happens on. Now you have to figure out why this happens. This is called debugging.
Maybe there is a mistake on another line, or maybe the algorithm has not been correctly implemented, or maybe the algorithm is being used outside of its applicable domain, or maybe that algorithm just is not correct for some cases ... there are lots of reasons why bugs occurs, but humans fix them by figuring out why they occur. Not just guessing, but checking all of the values: where is number defined? What values can it possible have? (this is not the same as asking "what values do I want it to have!). Are all of these values acceptable, or will some of them lead to zero indices ? How does the algorithm manage that: should it throw an error, use a default value, or do something else?
These are things that the author of the algorithm has to known and understand.
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!