Sorting an array without regard to the sign of the numbers

2 ビュー (過去 30 日間)
Patrick Benz
Patrick Benz 2021 年 10 月 11 日
回答済み: Patrick Benz 2021 年 10 月 11 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by