Min/Max with string match criteria

4 Ansichten (letzte 30 Tage)
OliverH
OliverH am 21 Jul. 2015
Beantwortet: Walter Roberson am 21 Jul. 2015
I want to find the minimum and maximum date for each unique string value.
e.g. X = ['a'; 'b']
Y = ['a'; 'a'; 'a'; 'a'; 'a'; 'b'; 'b'; 'b'; 'b'; 'b']
Z = [736000; 736001; 736002; 736003; 736004; 736012; 736013; 736014; 736015; 736016]
X is each unique string in Y.
Y and Z are the same size.
Z is the datenum.
Output is the min and max datenum for each entry in X.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Jul. 2015
[tf, idx] = ismember(Y, X); %not X, Y!
minZ = accumarray(idx(:), Z, [], @min);
maxZ = accumarray(idx(:), Z, [], @max);

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by