MATLAB: Change the order of array

change the order

I have M=[1,2 ;1,5; 2,4;2,5;4,5; 4,9;5,6;6,11;9,10;10,11] I want to change the order of numbers I want this answer N=[1,2;1,4;2,3;2,4;3,4;3,6;4,5;5,8;6,7;7,8]

Best Answer

[~,N] = ismember(M,unique(M(:)))