I want to arrange a 1st column of a matrix in descending order an the elements in the row is going to arrange itself according to change of the row of first vector

1 回表示 (過去 30 日間)
A= [3 2; 1 4; 2 6]
Taking the first coumn of matrix as base I want to change the other elements ie.
A=[ 3 2; 2 6; 1 4]
Ie entry to the rows going to arrange itself according to the first element of first column of matrix

採用された回答

Stephen23
Stephen23 2021 年 11 月 23 日
The simple MATLAB approach:
A = [3,2;1,4;2,6]
A = 3×2
3 2 1 4 2 6
B = sortrows(A,-1)
B = 3×2
3 2 2 6 1 4

その他の回答 (1 件)

KSSV
KSSV 2021 年 11 月 23 日
編集済み: KSSV 2021 年 11 月 23 日
A= [3 2; 1 4; 2 6] ;
[val,idx] = sort(A(:,1),'ascend')
val = 3×1
1 2 3
idx = 3×1
2 3 1
A = A(idx,:)
A = 3×2
1 4 2 6 3 2

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by