I have a question about gathering same numbers together in a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
the cyclist
el 5 de Nov. de 2019
Editada: the cyclist
el 5 de Nov. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!