sort cell array in descending order based on 2nd column

15 vues (au cours des 30 derniers jours)
jahanzaib ahmad
jahanzaib ahmad le 26 Mar 2019
Commenté : Adam Danz le 26 Mar 2019
i have cell array and want to sort it based on 2nd column .
i have tried this
[~,idx] = sort([AA{:,2}]);
idx([1:2:end,2:2:end]) = idx;
B = AA(idx,:);
but 2nd column in not in descending order .

Réponse acceptée

Adam Danz
Adam Danz le 26 Mar 2019
Modifié(e) : Adam Danz le 26 Mar 2019
The [65 x 2] cell array in your mat file is named "A1".
[~, idx] = sort([A1{:,2}], 'descend');
A1_descendingOrder = A1(idx,:)
  2 commentaires
jahanzaib ahmad
jahanzaib ahmad le 26 Mar 2019
thank you very much
Adam Danz
Adam Danz le 26 Mar 2019
You were so close!

Connectez-vous pour commenter.

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