Rearranging matrix in ascending order for value in a column

1 次查看(过去 30 天)
0.748151592823709 0.913337361501670 0.996134716626885 0.961898080855054
0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
Let's consider I have a matrix like this. I want to rearrange the matrix based on value in the last column in ascending order, so that I would look like below
0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433
0.748151592823709 0.913337361501670 0.996134716626885 0.961898080855054
I would do it manual for this case, but my data matrix is 500*8. Is there any option?

回答(1 个)

KSSV
KSSV 2016-11-24
k = [ 0.748151592823709 0.913337361501670 0.996134716626885 0.961898080855054
0.450541598502498 0.152378018969223 0.078175528753184 0.004634224134067
0.083821377996933 0.825816977489547 0.442678269775446 0.774910464711502
0.228976968716819 0.538342435260057 0.106652770180584 0.817303220653433];
[val,idx] = sort(k(:,end)) ;
iwant = k(idx,:)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by