MATLAB: Find the maximum value in each group of a big matrix

max

I have a big matrix and I'm looking for an easy way to group them by a certain way then find the maximum in each group. I have created this code but I got stuck. Anyway to help please. I need to know the indexes of all the maximum points to extract more information from the big matrix.
data = randn(10,1)*10;
edges = 0:5:35';
Y = discretize(data,edges);
[B,I] = sort(Y);
SortedMatrix = [B data(I)];

Best Answer

data = randn(10,1)*10;
edges = [-Inf, 0:5:35, Inf];
Y = discretize(data, edges);
Result = accumarray(Y, data, [], @max)
I'm confused that this does not work reliably with splitapply:
Result = splitapply(@max, data, Y)
It fails with an error message, if an interval is empty:
For N groups, every integer between 1 and N must occur at least
once in the vector of group numbers.