Subscript indices must either be real positive integers or logicals.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Kelly Kearney
el 22 de Jun. de 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 comentarios
Stephen23
el 23 de Jun. de 2016
Editada: Stephen23
el 23 de Jun. de 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.
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!