How to sortvalues in a variable based on another variable
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Chad Greene
el 11 de Jul. de 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).
0 comentarios
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!