使用Matlab计算数组中每行的频率

Tan*_*iel 3 arrays matlab unique

我有这个巨大的阵列.我在一个单独的数组中提取了唯一的行.现在我想创建一个向量来存储每个唯一行的出现.我怎么能这样做?尝试使用histc.我找到了tabulate,但只适用于矢量.

x=[62   29  64
    63  32  61
    63  32  61
    63  32  61
    63  31  62
    62  29  64
    62  29  64
    65  29  60
    62  29  64
    63  32  61
    63  32  61
    63  29  62
    63  32  61
    62  29  64
    ];

uA=unique(x)
[row, count] = histc(x,unique(x,'rows'))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:Edge vector must be monotonically non-decreasing.在其他几次尝试中也遇到此错误.

Div*_*kar 6

unique这种方式 -

[unique_rows,~,ind] = unique(x,'rows')
counts = histc(ind,unique(ind))
Run Code Online (Sandbox Code Playgroud)

unqiue_rows并且counts是您可能感兴趣的输出.

根据您提供的数据,它会产生 -

unique_rows =
    62    29    64
    63    29    62
    63    31    62
    63    32    61
    65    29    60
counts =
     5
     1
     1
     6
     1
Run Code Online (Sandbox Code Playgroud)

额外奖励:您可以通过避免第二次使用unique这种方式来提高性能-

counts = histc(ind,1:max(ind));
Run Code Online (Sandbox Code Playgroud)