combined sorting
조회 수: 13 (최근 30일)
이전 댓글 표시
For ex;I have an array A=[1:4] and B=[12:19:2:20].If I sort B in descending order B=[20 19 12 2].I want the corresponding positions in A to be swapped as well...ie A=[4 2 1 3].How do I achieve that?
댓글 수: 0
채택된 답변
Matt Tearle
2011년 4월 3일
[sortB,idx] = sort(B,'descend');
sortA = A(idx);
Or put the vectors into a matrix and use sortrows.
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!