Rearranging matrix in ascending order for value in a column

1 回表示 (過去 30 日間)
young jin Kwak
young jin Kwak 2016 年 11 月 24 日
回答済み: KSSV 2016 年 11 月 24 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by