changing sequence in sequence

4 ビュー (過去 30 日間)
Yigitalp Ozmen
Yigitalp Ozmen 2019 年 7 月 17 日
コメント済み: Yigitalp Ozmen 2019 年 7 月 17 日
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

回答 (1 件)

Steven Lord
Steven Lord 2019 年 7 月 17 日
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 件のコメント
Yigitalp Ozmen
Yigitalp Ozmen 2019 年 7 月 17 日
Could you share an example code? Thank you for your quick reply.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by