How do I sort the second layer of a 3D matrix based on the first layer?
Show older comments
I have a big matrix of values, and I need to sort the rows to run from smallest to largest. This would be easy, if it weren't for the fact that each value in the row is paired with a corresponding decimal value the second layer, and I can't lose the pairing.
Example: Say I need to sort this 3x2x2 array:
First layer
1 2
5 4
0 -1
Second Layer
0.5 0.3
0.7 0.2
0 0.8
Running "sort" on it would simply order the rows in both layers, whereas I would need to maintain the pairings (1 with 0.5, 2 with 0.3), etc:
First Layer
1 2
4 5
-1 0
Second Layer
0.5 0.3
0.2 0.7
0.8 0
Can anyone suggest an efficient way for me to do this?
1 Comment
Evan McAllister
on 8 May 2018
Accepted Answer
More Answers (0)
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!