Sorting an array without regard to the sign of the numbers

2 次查看(过去 30 天)
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?

采纳的回答

Patrick Benz
Patrick Benz 2021-10-11
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by