Sorting an array without regard to the sign of the numbers

2 views (last 30 days)
I have an Array of 7765 x 4 that I want to sort. It looks like this:
1110 -390.121000 -10.454900 -0.01882277
1501 3.187177047 5.32644003 167.2790029
1805 4.821873268 5.60381016 190.0584265
2109 4.722658634 5.56606016 190.5110412
2413 3.200538391 5.10077007 167.6860615
I want to sort it in a way that the largest value in terms of amount from columns 2 to 4 is in column 2. The problem is that I don't want to lose the sign of the values. For the example it should look like this in the end
1110 -390.121000 -10.454900 -0.01882277
1501 167.2790029 5.32644003 3.187177047
1805 190.0584265 5.60381016 4.821873268
2109 190.5110412 5.56606016 4.722658634
2413 167.6860615 5.10077007 3.200538391
Has anyone any Idea how I can do that?

Accepted Answer

Patrick Benz
Patrick Benz on 11 Oct 2021
Well ... if anyone else has issues understanding the documentation of "sort" when first reading it, here is how I solved it
test=sort(test(:,2:4),2,'descend','ComparisonMethod','abs');
pretty damn easy :D

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!