MATLAB: How to sort (ascending or descending) a list of ID numbers based on the value in a corresponding vector

arraydataMATLABsortvectors

Hello,
I have a 2 vectors: one is a 1 by n vector of item ID's and the other is a 1 by n vector of values corresponding with the item ID that I wish to sort. For example: IDs=[101 102 103 104 105] and v=[45 2 16 91 22] where each entry in the IDs vector corresponds to each entry in v (i.e. ID 101 corresponds with the value 45, ID 102 corresponds with the value 2 and so on). Lets say I want to sort(v). How would I make it so that each element in the IDs vector still matches up with the corresponding value in v after doing sort(v)? Does this make sence what I am asking?
Anything helps,
Thanks!

Best Answer

Index second output of sort() to ID.