%% Sort Complex Numbers
% Sort a matrix of complex numbers by absolute value and then by real part.
% Create a 100-by-2 matrix of random complex numbers.

valRange = [-10 10];
X = randi(valRange,100,2) + 1i*randi(valRange,100,2);

%
% Find the top 10 rows of the matrix. By default, topkrows compares the complex numbers by absolute value.

TA = topkrows(X,10)

%
% Find the top 10 rows of the matrix using only the real part of the complex numbers by specifying the 'ComparisonMethod' name-value pair.

TB = topkrows(X,10,'ComparisonMethod','real')

% Copyright 2012 The MathWorks, Inc.