Sort in ascending order for first column then descending order for the second column.

14 vues (au cours des 30 derniers jours)
Hi,
A=[1 1 1;
3 2 1;
1 3 1]
is there a way in matlab to sort rows of a matrix based on ascending order for the first column and then descending order for the second column, so the final matrix will look like this:
A=[1 3 1;
1 1 1;
3 2 1]

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 29 Mar 2014
A=[1 1 1; 3 2 1; 1 3 1]
B=sortrows(A,[1 -2])

Plus de réponses (0)

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