【问题标题】:Unique combinations of an array and number of occurences in matlabmatlab中数组和出现次数的唯一组合
【发布时间】:2016-06-02 10:54:17
【问题描述】:

我有一个像这样的输入数组

all = [0 0;0 3;6 6;6 0;13 0;12 12;3 0;0 6;6 6];

我需要找到每一行的唯一组合以及这种组合出现的次数,例如

output1 = [0 0;0 3;0 6;0 13;6 6;12 12];
output2 = [1;2;2;1;2;1];

为了获得独特的组合,我以这种方式使用了 sortunique 函数的组合

unique(sort(all ,2),'rows');

问题在于获取每个组合的出现次数。我尝试以这种方式使用hist函数

[a, b]= hist(all ,unique(sort(all ,2),'rows'));

但我得到了他的错误

错误使用 histc 边向量必须是单调非递减的。

hist 中的错误(第 121 行) nn = histc(y,edgesc,1);

有人可以帮我获得所需的输出吗?

谢谢

【问题讨论】:

    标签: arrays matlab


    【解决方案1】:

    在这种情况下,您不想使用完整的行。使用索引更容易。 unique 已经为您转换为索引。

    [output1,b,c]=unique(sort(all ,2),'rows')
    output2=hist(c,1:numel(b))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多