Sort an Array with sortrows ( ) with two columns
古いコメントを表示
Hey guys,
I'm sorting an 82x4 arraywith sortrows. I want it to be sorted in a descending way. First the second column shall be significant and for tiebreakers the third column.
My code is:
Knotenpaare=sortrows(Auswertung,[2 3],'descend')
where Auswertung is the array. The first 40 rows of the array are sorted beautifully. But at the moment the values in the second column switch from positive to negative the sorting changes.

Why are the values in the third column now ascending?
Is there a better way to sort these kinds of arrays ?
7 件のコメント
"Why are the values in the third column now ascending?"
Probably because the values in the second column are not the same. They might look the same when displayed to five significant digits, but have you actually compared them (e.g. diff, eq, etc.)?
Patrick Benz
2021 年 2 月 19 日
dpb
2021 年 2 月 19 日
Shouldn't matter, but try
Knotenpaare=sortrows(Auswertung,[2 3],{'descend','descend'})
just in case.
Attach the section of the data as a .mat file so folks can try to duplicate symptoms
Jan
2021 年 2 月 19 日
@Patrick Benz: I assume also, that the equally looking numbers -1.0424 are not identical, if you consider all decimal places. Please post the data as MAT file. The 6 relevant rows are enough to finde the difference.
Stephen23
2021 年 2 月 19 日
"The Values are exactly the same."
Until we test the actual data we have no reason to think that they are exactly the same values.
Please upload the data in a .mat file by clicking the paperclip button.
Patrick Benz
2021 年 2 月 24 日
編集済み: Patrick Benz
2021 年 2 月 24 日
dpb
2021 年 2 月 24 日
"Is there an option to cut the number after 5 digits off? and not only visual."
node_Num=sign(node_Num).*floor(abs(node_Num)*1E5)/1E5;
採用された回答
その他の回答 (1 件)
the cyclist
2021 年 2 月 19 日
1 投票
See my answer (and other comments) to this very similar question. (As with the comments above, the premise is that the displayed value is not sufficient to see a tiny difference between the numbers.)
カテゴリ
ヘルプ センター および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!