MATLAB: Arrange a matrix with repeated rows

matrix manipulation

Hi,experts
I have a raw matrix as:
a = [125 97
126 104
97 125
104 126];
I'm looking for an algorithm to manipulate this matrix with an output as:
a = [125 97
97 125
126 104
104 126];
just I want to put repeated row together. This is a small piece of a large matrix, but the structure is the same.
Thank you Kyle

Best Answer

[idx idx] = sortrows(sort(a,2));
a = a(idx,:);