changing sequence in sequence

1 visualización (últimos 30 días)
Yigitalp Ozmen
Yigitalp Ozmen el 17 de Jul. de 2019
Comentada: Yigitalp Ozmen el 17 de Jul. de 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

Respuestas (1)

Steven Lord
Steven Lord el 17 de Jul. de 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 comentario
Yigitalp Ozmen
Yigitalp Ozmen el 17 de Jul. de 2019
Could you share an example code? Thank you for your quick reply.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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!

Translated by