changing sequence in sequence

조회 수: 2 (최근 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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by