Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Iremsu Savas
Iremsu Savas le 5 Nov 2019
Modifié(e) : the cyclist le 5 Nov 2019
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

Réponses (1)

the cyclist
the cyclist le 5 Nov 2019
Modifié(e) : the cyclist le 5 Nov 2019
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.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by