MATLAB Answers

0

sort cell array in descending order based on 2nd column

Asked by jahanzaib ahmad on 26 Mar 2019
Latest activity Commented on by Adam Danz
on 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 .

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Adam Danz
on 26 Mar 2019
Edited by Adam Danz
on 26 Mar 2019
 Accepted Answer

The [65 x 2] cell array in your mat file is named "A1".
[~, idx] = sort([A1{:,2}], 'descend');
A1_descendingOrder = A1(idx,:)

  2 Comments

You were so close!

Sign in to comment.