changing sequence in sequence
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!