MATLAB: How to locate rows that has max values in r*2 matrix

matrix manipulation

I want to get the max values in a r*2 matrix. r is input from the user. Then, I want to get the complete row(s) where the maxima are. The example here may make it clear:
x = [1 7; 0 5; 9 -1];
n = max(x, [], 1); % Return the max value of each column
>> n = [9, 7] % The max values for columns 1 and 2
but I want to return the rows of the max values, so I want the result to be:
M=[1 7; 9 -1]
The rows in matrix x change based on input from the user, but the number of columns are fixed to 2.

Best Answer

E.g., assuming you always want two rows (which might be the same):
[~,rows] = max(x,[],1);
M = x(sort(rows),:);
If you don't want a row repeated, then simply add code to detect this and return only one row in that case.