Sort multiple arrays based on the next array

I have three separate arrays in matlab / octave and they are all related to each other.

I am trying to sort the values โ€‹โ€‹of an array a and b based on type c (therefore, when c is sorted, arrays a and b are sorted in the same order as array c).

Example: Original Array a= [1.2 2 3 4 5 6] b= [3 5 6 4.1 7 9] c= [2.2 1 9 6 8 3] 

Arrays a and b are based on type c (note that all arrays are sorted depending on the sort order of array c)

 Final Array that I want: a= [2 1.2 6 4 5 3] b= [5 3 9 4.1 7 6] c= [1 2.2 3 6 8 9] 

Aloha rick

PS: I use matlab / octave, if there is a better way to do this, please let me know

+7
sorting arrays multidimensional-array matlab octave
source share
1 answer
 [sorted, indices] = sort(c) % get your output with a(indices) b(indices) 
+10
source share

All Articles