Sort function does not return correct indices
5 ビュー (過去 30 日間)
古いコメントを表示
I am using the sort function to sort values in each row of a large matrix. The function returns the correct sorted matrix, but not always the correct indices.
The row highlighted in the screenshot below provides an example (columns 1-3 are the original matrix, columns 4-6 are the sorted matrix, and columns 7-9 are the indices). In row 870, the sorted values are in the correct order, but the indices are in the opposite order. Notice the function gives the correct answer for all other lines in this example.
What am I doing wrong?
[Usort,Uind]=sort(U,2,'descend');
Check=[U,Usort,Uind];

2 件のコメント
dpb
2019 年 11 月 24 日
編集済み: dpb
2019 年 11 月 24 日
We can't tell w/o data what generated the table...I've never observed such a problem...
Attach the raw dataset...
Which release are you using just on the most rarest of chances that a bug somehow did get introduced?
ADDENDUM: Actually 870 is NOT wrong...see Answer. I'm guessing you're looking for sorting by decreasing absolute value, not magnitude.
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!