How to find subgroup min or max

2 Ansichten (letzte 30 Tage)
Tiina
Tiina am 8 Mär. 2016
Kommentiert: Stephen23 am 8 Mär. 2016
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 Kommentar
Jan
Jan am 8 Mär. 2016
The question is not clear. Please explain how C is obtained.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Mär. 2016
Bearbeitet: Stephen23 am 8 Mär. 2016
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 Kommentare
Tiina
Tiina am 8 Mär. 2016
great thx, although i dont know wat "any" means with the bsxfun
Stephen23
Stephen23 am 8 Mär. 2016
Read the any documentation.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by