我有一组数据,其中包含我想删除存在子集的超集的集合,如下所示:
a{1} = [5]
a{2} = [4 11 14]
a{3} = [1]
a{4} = [5 16]
a{5} = [5]
a{6} = [11 16]
a{7} = [11]
a{8} = [16]
a{9} = [9 14 17]
a{10} = [14]
[ii, jj] = ndgrid(1:numel(a));
s = cellfun(@(x,y) all(ismember(x,y)), a(ii), a(jj));
s = triu(s,1); %// count each pair just once, and remove self-pairs
similarity = a(~any(s,1));
celldisp(similarity)
结果如下:
a{1} = [5]
a{2} = [4 11 14]
a{3} = [1]
a{4} = [11 16]
a{5} = [11]
a{6} = [16]
a{7} = [9 14 17]
a{8} = [14]
正如输出所示,仍然有应该删除的超集,即a{2}
因为a{5}
contains11
是它的子集,a{4}
应该删除因为a{5}
contains11
和a{6}
contains16
以及a{7}
应该删除,因为a{8}
contains subset 14
。
预期输出是
a{1} = [5]
a{2} = [1]
a{3} = [11]
a{4} = [16]
a{5} = [14]
任何人都可以帮助如何修复此代码,以便我可以获得准确的结果集。谢谢