MATLAB: Sorting an array and their corresponding

arraysort

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.

Best Answer

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