考虑以下数组:
a = [1 2 3;
1 1 1;
1 2 3]
如何计算此数组中唯一行的数量?示例中的答案是 2,因为 [1 2 3]
行重复了两次。
最佳答案
使用unique
使用 'rows'
属性获取唯一行并通过获取输出行方向的 size
来计算它们。
uniquerows = size( unique(a,'rows'), 1)
或者,您可以使用 numel
计算 unique
的第二个输出:
[~,c] = unique(a,'rows')
uniquerows = numel(c)
关于matlab - 计算矩阵中的唯一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31344975/