简体   繁体   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?

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.

相关问题 如何从属于A的单元格B中删除所有向量或从A中包含在一个向量中的向量? - How to remove all vectors from a cell B which belong to A or which are contained in one vector from A? 如何找到包含至少一个向量B的元素的单元格A的向量? - How to find the vectors of the cell A that contain at least one element of the vector B? Matlab:如何从2个向量中找到所有可能的组合? - Matlab: How to find all possible combinations from 2 vectors? 如何找到具有固定分量的矩阵的所有可能组合 - How to find all possible combinations of a matrix with fixed components Matlab:如何将向量应用于细胞中的每个向量? - Matlab: How to Apply vector to each vector in cell? 如何在Matlab中查找重复的细胞向量? - How to find repeated cell vectors in matlab? 查找B中包含但不在A - MATLAB中的列向量 - Find column vectors contained in B but not in A - MATLAB 从矩阵M,如何找到向量Vi的像元,该向量指示每列Ci中值2的索引线? - From the matrix M, how to find the cell of vectors Vi, indicating the index line of the value 2 in each column Ci? “ num”和“ den”属性的值必须是行向量或行向量的单元格数组,其中每个向量均为非空 - The values of the “num” and “den” properties must be row vectors or cell arrays of row vectors, where each vector is nonempty 如何在特定条件下生成n个向量的所有可能组合 - How to generate all possible combinations of n vectors following a particular condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM