我有这个庞大的阵列。我在一个单独的数组中提取了唯一的行。现在我想创建一个向量来存储每个唯一行的出现。我怎么能这样做?尝试使用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'))
我收到以下错误:Edge vector must be monotonically non-decreasing.
在其他几次尝试中也遇到此错误。
答案 0 :(得分:6)
以这种方式使用unique
-
[unique_rows,~,ind] = unique(x,'rows')
counts = histc(ind,unique(ind))
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
加分:您可以避免以这种方式第二次使用unique
来改善效果 -
counts = histc(ind,1:max(ind));