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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by