Sorting an array and their corresponding

1 view (last 30 days)
Ko Fa
Ko Fa on 28 Jul 2020
Answered: KSSV on 28 Jul 2020
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.

Accepted Answer

KSSV
KSSV on 28 Jul 2020
[val,idx] =sort(a) ;
iwant = b(idx) ;

More Answers (0)

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!