how to sort an array of elements corresponding to another array in increasing order ?

if a= -1 0 2 -3 5 -10
and b= 2 -3 5 0 4 1
are two corresponding arrays . how to sort values of (b) in an increasing order with keeping its corresponding values in array (a).
the answer should be like this:
a= 0 -3 -10 -1 5 2
b= -3 0 1 2 4 5

 채택된 답변

Have a look at the documentation for sort. You can do it as follows:
[b,idx]=sort(b)
a=a(idx)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2019년 12월 13일

답변:

2019년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by