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!