필터 지우기
필터 지우기

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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by