Sort rows without sortrows function in MATLAB

4 ビュー (過去 30 日間)
Noor Fatima
Noor Fatima 2022 年 10 月 13 日
コメント済み: Noor Fatima 2022 年 10 月 13 日
The following is the data set say A
A =
9361 8366
9361 28317
9364 27948
9364 8735
9365 29127
9365 7556
9366 1870
9366 34813
9367 1825
9367 34858
9368 15168
9368 21515
if first coordinate is same then I want to arrange w.r.t to ascending order of second coordinate.
It can be done with, sort and sortrows command like
B = sortrows(A);
But need some other approach, please.
The output should be
B =
9361 8366
9361 28317
9364 8735
9364 27948
9365 7556
9365 29127
9366 1870
9366 34813
9367 1825
9367 34858
9368 15168
9368 21515

回答 (1 件)

KSSV
KSSV 2022 年 10 月 13 日
A = [9361 8366
9361 28317
9364 27948
9364 8735
9365 29127
9365 7556
9366 1870
9366 34813
9367 1825
9367 34858
9368 15168
9368 21515];
[val,idx] = sort(A(:,1)) ;
iwant = A(idx,:)
iwant = 12×2
9361 8366 9361 28317 9364 27948 9364 8735 9365 29127 9365 7556 9366 1870 9366 34813 9367 1825 9367 34858
  2 件のコメント
Noor Fatima
Noor Fatima 2022 年 10 月 13 日
@KSSV Thank you very much for the comment.
But I can't use any builtin function, i.e., sort or sortrows
Is there any other way please?
Noor Fatima
Noor Fatima 2022 年 10 月 13 日
Furthermore, sorry the output is not correct it is the same as input.

サインインしてコメントする。

カテゴリ

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