sorting matrix in ascending order based on column 1 (and ascending order also for column 2)

1 vue (au cours des 30 derniers jours)
Hi all, is there a way to sort A in ascending order based on column 1, allowing its other columns to follow with it
A = [1 2 5
1 3 3
2 3 12
1 4 2];
results should be:
B = [1 2 5
1 3 3
1 4 2
2 3 12
];

Réponse acceptée

the cyclist
the cyclist le 14 Sep 2019
Modifié(e) : the cyclist le 14 Sep 2019
Use the sortrows command.
B = sortrows(A,1);

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by