Subscript indices must either be real positive integers or logicals.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Kelly Kearney
2016-6-22
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 个评论
Stephen23
2016-6-23
编辑:Stephen23
2016-6-23
@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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!