How to sortvalues in a variable based on another variable

2 views (last 30 days)
Suppose, I have 2 cell variables:
A{1}=
46 25 35 25
22 1 11 1
22 1 11 1
46 25 35 25
B{1}=
3 4 5 6
3 7 5 8
3 2 5 2
3 8 5 9
I would like to sort the values in B based on the values in A (in ascending order) by row. I have provided an example of the output as follow:
resultantA{1}=
25 25 35 45
1 1 11 22
1 1 11 22
25 25 35 46
resultantB{1}=
4 6 5 3
7 8 5 3
2 2 5 3
8 9 5 3

Answers (1)

Chad Greene
Chad Greene on 11 Jul 2014
It's nice that you have given an example, but I need help understanding how you have sorted things in your example.
The sort and sortrows functions will return indices which describe how A is sorted. Then you can sort B like Bsorted = B(ind).

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!