Effacer les filtres
Effacer les filtres

How to sortvalues in a variable based on another variable

2 vues (au cours des 30 derniers jours)
RDG
RDG le 11 Juil 2014
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

Réponses (1)

Chad Greene
Chad Greene le 11 Juil 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).

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by