I have three separate arrays in matlab/octave and they are all associated with each other.
I'm trying to sort the array values of a and b based on the sort of c (so when c is sorted, a and b arrays are sorted in the same order as the c array).
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 the sort of c (notice all the arrays are sorted based on the order Array c is sorted in)
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'm using matlab/octave if there is a better way to do this please let me know
[sorted, indices] = sort(c)
% get your output with
a(indices)
b(indices)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With