我有set4变量(4 x 2双)。当我对其进行排序时,每个元素的第二个属性也会被排序。我只需要排序第一个属性。例如,
set4=[ 10 1; 20 1; 5 2; 15 2];
sort(set4)
输出:
ans =
5 1
10 1
15 2
20 2
但是我的预期输出是,ans =
5 2
10 1
15 2
20 1
我该怎么做?
set4=[ 10 1; 20 1; 5 2; 15 2]; %example data
[set,in] = sort(set4(:,1)); %sort just the first column and get the indices
set(:,2)= set4(in,2) %use the indices to re-order the second column
set =
5 2
10 1
15 2
20 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句