Sorting two simple matrices
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi! I need to sort matrix A from least to greatest; however, the values are tied to matrix B. How can I can make B adjust with a matrix A sort.
Matrix A and B are the starting values, and A' and B' are the desired answer.
A = [ 2, 3, 1, 4]
B = [ 6, 5, 1, 10]
A' = [ 1, 2 , 3, 4]
B' = [ 1, 6, 5, 10]
댓글 수: 0
채택된 답변
James Tursa
2021년 2월 23일
편집: James Tursa
2021년 2월 23일
Use the 2nd output argument of the sort( ) function, which has the indexing. E.g.,
[Asorted,ix] = sort(A);
Bsorted = B(ix);
추가 답변 (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!