How to find subgroup min or max

2 ビュー (過去 30 日間)
Tiina
Tiina 2016 年 3 月 8 日
コメント済み: Stephen23 2016 年 3 月 8 日
group_id=[1 1 1 2 2 3 3 3]';
B=[ 5 6 7 4 1 2 2 3]';
output: C=[ 5 0 0 0 1 2 2 0]';
  1 件のコメント
Jan
Jan 2016 年 3 月 8 日
The question is not clear. Please explain how C is obtained.

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

採用された回答

Stephen23
Stephen23 2016 年 3 月 8 日
編集済み: Stephen23 2016 年 3 月 8 日
X = [1;1;1;2;2;3;3;3];
B = [5;6;7;4;1;2;2;3];
A = accumarray(X,B,[],@min);
Y = any(bsxfun(@eq,A,B.'));
C = zeros(size(B));
C(Y) = B(Y)
where the output is
C =
5
0
0
0
1
2
2
0
  2 件のコメント
Tiina
Tiina 2016 年 3 月 8 日
great thx, although i dont know wat "any" means with the bsxfun
Stephen23
Stephen23 2016 年 3 月 8 日
Read the any documentation.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by