vector confusion
2 ビュー (過去 30 日間)
古いコメントを表示
I have a vector A whose values are indices for vector P.
Say A = 2 occurs 10 times.
If I do:
P(A) = P(A) + 1
P(2) = 1 % not 10
I believe I understand why this is happening. Is there a solution without going into FOR loops? A could be quite large.
2 件のコメント
the cyclist
2011 年 9 月 22 日
I do not understand what you mean by "A = 2 occurs 10 times". Can you write out code for what you mean?
採用された回答
Walter Roberson
2011 年 9 月 22 日
Especially if you are starting with an all-zero array, use
P = accumarray(A(:),1);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!