# Sort a Matrix by the first column connecting the row elements so that the elements of the second column 'follow' those of the first.

조회 수: 2(최근 30일)
Alex Perrakis 2021년 9월 14일
댓글: Alex Perrakis 2021년 9월 14일
Hello Guys, i have a two column Matrix, where the first column is the diameter of some particles and the second column is Extiction. So the elements of the second column correspond to those of the first. My question is, is there a function that lets me sort the first column in ascending or descending order (does not matter) so that the corresponding value of extiction 'follows'? thank you very much.

댓글을 달려면 로그인하십시오.

### 채택된 답변

KSSV 2021년 9월 14일
A = rand(10,2) ;
[val,idx] = sort(A(:,1)) ;
iwant = A(idx,:)
##### 댓글 수: 1표시숨기기 없음
Alex Perrakis 2021년 9월 14일
Thanks bro it worked wonders

댓글을 달려면 로그인하십시오.

### 범주

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by