changing sequence in sequence

1 vue (au cours des 30 derniers jours)
Yigitalp Ozmen
Yigitalp Ozmen le 17 Juil 2019
Commenté : Yigitalp Ozmen le 17 Juil 2019
Hello everyone;
I have 4 10x1 arrays. I'd like to sort j values according to ascending order of Rj. However, in this sorted sequence, if more than one job have the same Rj values, the sequence of ONLY these jobs should be reordered according to ascending order of these jobs' Dj values. Moreover, if there is a tie in Dj values, same approach should be applied according to Pj values. Not likely but possible, if Pj values are also equal these j values should be ordered according to their j indices.
An example:
Rj=[10;10;5;9;2;5;10;8;10;7];
Dj=[1;9;10;9;8;8;4;7;2;8];
Pj=[1;3;1;1;9;7;4;10;1;5];
j=[1;2;3;4;5;6;7;8;9;10];
Index_Sorted_Rj=[5;3;6;10;8;4;1;2;7;9;];
Sorted_Rj=[2;5;5;7;8;9;10;10;10;10]
From this point j values having Rj values equal to 5 and 10 should be ordered according to their Dj values.
Therefore new sequence should be [5;6;3;10;8;4;1;9;7;2]
For this case we stopped at Dj. Because, there is no j values having the same Dj values.
I hope i explained my problem accurately.
Thanks

Réponses (1)

Steven Lord
Steven Lord le 17 Juil 2019
Concatenate the variables you want to consider in the sorting order into one matrix, with each variable a separate column.
Call sortrows with two outputs on that matrix, specifying the COL input to represent the order in which each column should be considered as a "tiebreaker".
Use the second output from the sortrows call to reorder the original variable.
  1 commentaire
Yigitalp Ozmen
Yigitalp Ozmen le 17 Juil 2019
Could you share an example code? Thank you for your quick reply.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical 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