I have a question about gathering same numbers together in a matrix

1 回表示 (過去 30 日間)
Iremsu Savas
Iremsu Savas 2019 年 11 月 5 日
編集済み: the cyclist 2019 年 11 月 5 日
Hello,
I have a matrix with 104x3 format.
In the third column I have values from 1 to 4. and the first 2 column I have different values. Let me give a quick and basic example:
15 20 1
45 30 1
12 10 1
48 78 3
18 16 4
20 56 3
13 14 1
17 85 3
14 55 2
33 6 4
45 7 4
and so on.
What I would like to do is to see the matrix in a form like, all the 1 values that are in the third column are one under the other, after that I want to see two's and then 3's and 4's like that:
x x 1
x x 1
x x 1
x x 2
x x 2
x x 3
x x 3
x x 3
x x 4
Is there a quick way to make this happen?
Thank you

回答 (1 件)

the cyclist
the cyclist 2019 年 11 月 5 日
編集済み: the cyclist 2019 年 11 月 5 日
If M is your matrix, then
M_sorted = sortrows(M,3)
will output M sorted by the 3rd column, maintaining the order of the other two columns. See the documentation for sortrows for details.

カテゴリ

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