help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: sortcom


From: Allen.Windhorn
Subject: RE: sortcom
Date: Mon, 22 Apr 2013 17:32:04 +0000

Urs,

From: address@hidden [mailto:address@hidden On Behalf Of Urs Hackstein

> let x be a vector of complex numbers. I want to sort these
> complex numbers by its real parts, i.e. as -2+32*i, -1+3*i,
> 2+30*i, .... for example.
> sort(x) however sorts complex numbers by its absolute value
> and sort(real(x)) gives -2,-1,1

Assuming x is a column vector, let ax = [real(cx), imag(cx)];
Then sorted array sx = sortrows(ax) (sorts by first column, which
is the real part -- you can change this).
then the complex sorted array is scx = complex(sx(:,1), sx(:,2))

Regards,
Allen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]