MATLAB: Finding the mean and max

mean and max

suppose i have a matrix where the first column is x(:,1)=[ 1 1 1 2 2 1 1 3 1 ] and second column is x(:,2)=[ 2 3 2 4 6 9 7 8 9];
i want the output as y(:,1)=[ 1 2 3 ], y(:,2)=[ 9 6 8] and y(:,3)=[5.33 5 8];
the first column should be the values from first column of x reduced to a single value and in ascending order, the second column should be the highest number from the second column of x for a particular value in first input column. for ex. for all the 1's in first column of x should return one max value from the second column of x. the third column should contain the means of the second column of x for a particular value in first column of x. same example as given.

Best Answer

The first column you can achieve with unique, the second and third can be done with accumarray.
x=[ 1 1 1 2 2 1 1 3 1 ; 2 3 2 4 6 9 7 8 9]';
[col1,~,ind]=unique(x(:,1));
col2=accumarray(ind,x(:,2),[],@max);
col3=accumarray(ind,x(:,2),[],@mean);
y=[col1 col2 col3]