フィルターのクリア

Averaging values in rank orderings with repeats

2 ビュー (過去 30 日間)
Paul Fishback
Paul Fishback 2013 年 9 月 24 日
I'm wondering if there is a straightforward way for me to complete the following task.
Suppose u=[1,3,2,2,4,7,2,5] and I wish to create a vector of rank orderings that accounts for the fact that the three 2's are tied for ranks 2, 3, and 4 by using the average of these three ranks, (2+3+4)/3=3 in each corresponding entry.
More specifically, I want the rank ordering vector to be [1,5,3,3,6,8,3,7]. Notice how there is no 2 and no 4.

採用された回答

Kelly Kearney
Kelly Kearney 2013 年 9 月 24 日
The accumarray function should do what you want:
u = [1,3,2,2,4,7,2,5];
nu = length(u);
rank = (1:nu)';
ravg = accumarray(sort(u'), rank, [nu 1], @mean);
ravg(u)
  2 件のコメント
Paul Fishback
Paul Fishback 2013 年 9 月 24 日
Thanks! Not only for such a quick answer, but also for introducing me to the accumarray command.
Paul Fishback
Paul Fishback 2013 年 9 月 24 日
The first argument for accumarray has to be a vector of positive integers. What if this were not the case for my vector u?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by