Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 按每个值出现的时间对向量进行排序_Matlab_Sorting - Fatal编程技术网

Matlab 按每个值出现的时间对向量进行排序

Matlab 按每个值出现的时间对向量进行排序,matlab,sorting,Matlab,Sorting,我们有以下情况: Q = [idxcell{:,1}]; Sort = sort(Q,'descend') Sort = Columns 1 through 13 23 23

我们有以下情况:

    Q = [idxcell{:,1}];     
    Sort = sort(Q,'descend')                                                                                                                       
    Sort =
          Columns 1 through 13
            23    23    22    22    20    19    18    18    18    18    17    17    17
          Columns 14 through 26
            15    15    14    14    13    13    13    12    12    12    11    10     9
          Columns 27 through 39
             9     9     8     8     8     8     8     7     7     7     7     7     7
          Columns 40 through 52
             7     6     6     6     5     4     4     3     3     3     3     2     2
          Columns 53 through 64
             2     2     2     2     2     2     2     1     1     1     1     1
我们如何根据矩阵值的重复次数对其排序

等待结果应为:

repeatedSort =  2(9) 7(7) 1(5) 8(5) 3(4) 18(4) 6(3) 9(3) 12(3) 13(3) 17(3) 4(2) 14(2) 15(2) 22(2) 23(2) 5(1) 10(1) 11(1) 19(1) 20(1)
      or 
repeatedSort = 2 7 1 8 3 18 6 9 12 13 17 4 14 15 22 23 5 10 11 19 20

提前感谢您。

这里有一种方法:

d      = randi(10,1,30); %Some fake data
n      = histc(d,1:10);
[y,ii] = sort(n,'descend');

disp(ii) % ii is now sorted according to frequency
您可以使用统计工具箱中的函数,然后调用按频率排序

例如:

x = randi(10, [20 1]);    %# random values
t = tabulate(x);          %# unique values and counts
t = t(find(t(:,2)),1:2);  %# get rid of entries with zero count
t = sortrows(t, -2)       %# sort according to frequency
结果,其中第一列是唯一值,第二列是它们的计数:

t =
     2     4     %# value 2 appeared four times
     5     4     %# etc...
     1     3
     8     3
     7     2
     9     2
     4     1
     6     1

这些值的范围是否限制在0到1000之间,因为如果是这样的话,您可以对它们进行桶排序。@datdo在这种情况下,限制为100 yes.woops。我误解了这个问题。Bucket sort不是一种方法,它只会返回相同的向量。谢谢你,这个解决方案也是非常有效的@Amro