%% Complex Matrix
% Create a matrix containing complex numbers, and sort the rows of the matrix in ascending order based on the elements in the first column. Since the magnitudes of A(1,1) and A(3,1) are equal, sortrows computes their angles to break the tie.

A = [1+2i 3+i i; 2+10i 6i 2+5i; 2+i 4 3+3i]

%

B = sortrows(A)

%

angle(A(1,1))

%

angle(A(3,1))

%
% Use the 'real' option to sort the rows of A by their real part. Since A(2,1) and A(3,1) have equal real parts, sortrows uses the imaginary part to break the tie.
%

C = sortrows(A,'ComparisonMethod','real')

%

imag(A(2,1))

%

imag(A(3,1))

% Copyright 2012 The MathWorks, Inc.