Sort a Matrix based on a column

I want to sort a matrix. Actually I want to sort the last column and all the rest columns based on the last. Has anyone idea about this???

 采纳的回答

[lastvals, idx] = sort(A(:,end));
sortedA = A(idx,:);

2 个评论

Sorry I had the index order reversed. It is fixed in my Answer now.
[Kris zenitis commented]
I ve got a matrix 4000x9. When i tried your solution i got Index exceeds matrix dimensions.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by