繁体   English   中英

对于单元格A的每个向量,如何查找单元格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]};

对于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]包含在B{2}

[6 21]包含在B{1}

尝试这个:

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

结果将在C 例如,运行celldisp(C{1})以查看A{1}的结果。

该代码采用A每个向量,并使用nchoosek查找所有可能的组合。 然后,它检查是否任何组合具有包含在中的任何载体的所有值B ,返回其在ONT中的剩余组合B ,并将它们植入C

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM