[英]For each vector of the cell A, How to find all possible combinations of its components that are not contained in vectors of the cell B?
For each vector of the cell A
, How to find all possible combinations of its components that are not contained in vectors of the cell B
? 对于单元格
A
每个向量,如何找到单元格B
向量中不包含的所有成分的所有可能组合?
A = {[2 3 6 21],[66 4 2 7],[84 56 66 47 45]};
B = {[5 6 9 20 21],[7 85 14 2 3],[5 66 84 10 23 35 56],[5 6 87 14 21 29]};
For A{1}
, all possible combinations which satisfy the condition: 对于
A{1}
,满足条件的所有可能的组合:
{[2 6],[2 21],[3 6],[3 21],[2 6 21],[2 3 6],[2 3 21],[3 6 21],[2 3 6 21]}
[2 3]
is contained in B{2}
[2 3]
包含在B{2}
[6 21]
is contained in B{1}
[6 21]
包含在B{1}
Try this: 尝试这个:
C = cell(1, numel(A));
for ii = 1:numel(A)
aux = arrayfun(@(x) num2cell(nchoosek(A{ii}, x), 2)', 1:numel(A{ii}), 'Un', 0);
aux = [aux{:}];
C{ii} = aux(~cellfun(@(a) any(cellfun(@(b) all(ismember(a, b)), B)), aux));
end
The result will be in C
. 结果将在
C
。 Run celldisp(C{1})
to see the result for A{1}
, for example. 例如,运行
celldisp(C{1})
以查看A{1}
的结果。
This code takes every vector in A
and find all possible combinations using nchoosek . 该代码采用
A
每个向量,并使用nchoosek查找所有可能的组合。 Then, it checks if any combination has all values contained on any vector of B
, returning the remaining combinations which are ont in B
and putting them into C
. 然后,它检查是否任何组合具有包含在中的任何载体的所有值
B
,返回其在ONT中的剩余组合B
,并将它们植入C
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.