MATLAB Answers

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
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.


Sign in to comment.

Accepted Answer

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


Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!