Given a list of complex numbers z, return a list zSorted such that the numbers that are farthest from the origin (0+0i) appear first.
So if z is
z = [-4 6 3+4i 1+i 0]
then the output zSorted would be
zSorted = [6 3+4i -4 1+i 0]
It is useful to mention sort in 'descending' order of distance from origin.
Writing a solution whose size is so close to Leading solution is such a happy thing.
which leading solutions size is always 7 :S
Interesting. If you leave the 'ComparisonMethod','abs' it's still correct (size is 13).
Though, I believe this is the shortest, universally correct solution.
I keep receiving 'Matrix dimensions must agree' when using c(c==-d)... it seems to work fine in matlab, but not on here. Any ideas?
Note that "c(c==-d) = d" means that c and d must be same size or d is scalar. Moreover if d is not a scalar, then all "c==-d" must be true. This code seems to work in rare case, when one value is negative real number, and the rest are positive real numbers, but I have not tested it.
This is like the 'War & Peace' solution. I like it!
where is the problem here? it works on matlab
The function has to be named "complexSort".
Thanks for sharing
i have ran this solution in my MATLAB 2012Ra it's showing the desired result. then , why it is considerd incorrect here?
It looks like the function name has to have a capital S in it.
Simple and elegant, i like it
i keep learning new features...
Maximum value in a matrix
Free passes for everyone!
Flip the vector from right to left
A Simple Tide Gauge with MATLAB
Spot the First Occurrence of 5
Get the area codes from a list of phone numbers
Reverse Run-Length Encoder
Connect Four Win Checker
Replace NaNs with the number that appears to its left in the row.
Return a list sorted by number of occurrences
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office