Sorting an array and their corresponding

kinda stupid question but I couldnt figure it out,
I have two arrays, say
a = [5;10;1]
b = [0.1;0.2;0.3]
Now I am trying to sort the first array using sort and I want the corresping elements in array b sort with their corresponding element in a them, so if I do
sort(a)
I want the output to be
a = [1;5;10]
b = [0.3;0.1;0.2]
The corresponding elements in element b should stick with their original elemnt in a.
Any help is greatly appreciated.

 채택된 답변

KSSV
KSSV 2020년 7월 28일

0 개 추천

[val,idx] =sort(a) ;
iwant = b(idx) ;

추가 답변 (0개)

카테고리

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

태그

질문:

2020년 7월 28일

답변:

2020년 7월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by