簡體   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