MATLAB: Min/Max with string match criteria

MATLABmin max strcmp

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.

Best Answer

[tf, idx] = ismember(Y, X); %not X, Y!
minZ = accumarray(idx(:), Z, [], @min);
maxZ = accumarray(idx(:), Z, [], @max);