Sort with respect to identical elements in a column.

1 回表示 (過去 30 日間)
Hari krishnan
Hari krishnan 2018 年 10 月 18 日
コメント済み: Hari krishnan 2018 年 10 月 18 日
I have a matrix as shown below. The first column contains identity of objects and the second and third column corresponds to there detection times. What i want to do is to keep all the elements corresponds to the identical elements in the first column together.
eg: a = [51, 1.5, 3.8; 52, 1.8, 9.6; 53, 2.1, 8.8; 51, 3.5, 9.9; 54, 8.5, 10.23,51, 1.5, 3.8 ];
Is there a way to do this rather than using for loops and conditions? Any help will be appreciated.

採用された回答

Stephen23
Stephen23 2018 年 10 月 18 日
編集済み: Stephen23 2018 年 10 月 18 日
>> a = [51,1.5,3.8;52,1.8,9.6;53,2.1,8.8;51,3.5,9.9;54,8.5,10.23;51,1.5,3.8]
a =
51 1.5 3.8
52 1.8 9.6
53 2.1 8.8
51 3.5 9.9
54 8.5 10.23
51 1.5 3.8
>> sortrows(a) % sort by 1st col, 2nd col, etc.
ans =
51 1.5 3.8
51 1.5 3.8
51 3.5 9.9
52 1.8 9.6
53 2.1 8.8
54 8.5 10.23
>> sortrows(a,1) % sort only by 1st col.
ans =
51 1.5 3.8
51 3.5 9.9
51 1.5 3.8
52 1.8 9.6
53 2.1 8.8
54 8.5 10.23

その他の回答 (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